change time format

linkithub9 months ago

can anyone tell me how i change time format and which file contain those time parameters.
right now i got like this time format
[serverTime] => 2024-02-15T04:56:38.555+00:00
[deviceTime] => 2023-06-20T03:39:54.000+00:00
[fixTime] => 2023-06-20T03:39:54.000+00:00

i need to change like this so help me which file contain .....

[serverTime] => 1707915760450
[deviceTime] => 1707915760450
[fixTime] => 1707915760450

samaidha9 months ago

Assuming you are using the Default Traccar Web Application,
their documentations gives great insight: https://www.traccar.org/architecture/, on how Traccar App is ensembled.
You might find this link also helpful: https://www.baeldung.com/java-convert-date-unix-timestamp.

Udo4 months ago

If I understand the architecture correctly, this means that the Traccar server uses and stores UTC and the web app etc. is/must be converted to the desired time zone?

Anton Tananaev4 months ago

Traccar does not store UTC time.

Udo4 months ago

Is it better to say that the Traccar server processes and stores the timestamps as Epoch Time or POSIX Time, or is that also wrong?

Otherwise, I am surprised that all times in the web app are correctly displayed as CET, as defined in traccar.xml <entry key='timezone'>Europe/Berlin</entry>, but in MariaDB the times are stored as - 2 hours (i.e. UTC) and also all timestamps in the events submitted via JSON, including those from the iPhone client app, are converted to UTC. Where is my mistake in thinking?

Anton Tananaev4 months ago

What is the difference between Epoch Time and POSIX Time?

Udo4 months ago

Epoch Time and POSIX Time are terms that are often used interchangeably, but they refer to specific concepts in time representation within computing.

Epoch Time

  • Definition: Epoch Time generally refers to the starting point used to measure time in a particular system.
  • Common Example: In Unix systems, the epoch is 00:00:00 UTC on 1 January 1970.
  • Usage: Epoch Time is used as a baseline for computing the number of seconds that have elapsed since this starting point.

POSIX Time

  • Definition: POSIX Time is a standardized way of representing time, defined by the POSIX (Portable Operating System Interface) standard.
  • Specification: POSIX time is the number of seconds that have elapsed since the Unix epoch (00:00:00 UTC on 1 January 1970), not counting leap seconds.
  • Usage: It is widely used in Unix-like operating systems and is essential for ensuring compatibility and consistency across different systems.

Key Differences

  • Scope: "Epoch Time" is a broader concept that can refer to the starting point of time in any system, while "POSIX Time" specifically refers to the standard time representation in POSIX-compliant systems.
  • Standards: POSIX Time adheres to the POSIX standard, ensuring a consistent way to represent and manipulate time across systems that follow this standard.
  • Leap Seconds: POSIX Time does not account for leap seconds, while the term "Epoch Time" does not inherently specify how leap seconds are handled.

In summary, Epoch Time is a general concept, while POSIX Time is a specific implementation of this concept according to POSIX standards.

Anton Tananaev4 months ago

Sounds like you don't understand the difference.

Udo4 months ago

Let's say yes, otherwise I wouldn't have asked ;-)

Thinking constructively, get we closer to the answer if I ask whether it would be useful to take the server's time setting into account for the JSON event forward?
Possibly configurable, with default setting FALSE.

Anton Tananaev4 months ago

OK. Now we can move to your invalid configuration entry. Where did you get it from?

Udo4 months ago

I usually go the documentation and forum search route. In the meantime, however, I also like to have code generated by ChatGPT 4o, and use it more and more for detailed questions.

ChatGPT 4o answers the question of timecode for the Traccar server in great detail and, among other things, specifically with

<config>  
    ...
   <entry key='server.timezone'>Europe/Berlin</entry>
    ...
</config>

but also with the note to check the error log. I may have been too blind to find an error message.

Anton Tananaev4 months ago

You should always verify what you get from forum or ChatGPT with the original source - the official documentation. Both configuration options you listed are complete nonsense and don't exist.

Udo4 months ago

You're absolutely right, but unfortunately it's not very easy to find in the documentation.
Of course, you can also find statements like this from you

tananaev commented on Nov 10, 2015
Traccar always stores UTC time.
https://github.com/traccar/traccar/issues/1522#issuecomment-155589269

which, admittedly from 2015, cannot be reconciled with what you wrote here 2 days ago.
Traccar does not store UTC time.

So I ask myself, where exactly is the error and is this wrong Timezone entry really relevant?
Is my helplessness understandable?

Anton Tananaev4 months ago

If you just take statements without context, of course it won't make any sense. But if you read full threads, it will be clear. The first reference is specifically about protocol decoder and in that context, we're expecting UTC timezone from devices in most cases. The second reference (this thread) is about the data we store in the database. In that context we don't include any timezone information, so it's up to your database to decide what format it stores it.

In most cases if you see the wrong time, it means that there's some issue in communication between device and server. In vast majority of cases it means that your device is not reporting UTC time, which is what server expects (in most cases).

Udo4 months ago

That sounds logical, but unfortunately it is not. Where else do you store timestamps outside the database?

Why you then write the timestamp minus 2 hours in the database, which is set to CET time zone by system setting, is not really understandable for me.

Let's get back to the original question. The web app shows the correct time - CET for my installation. So everything is fine and correct!

The same time minus 2 hours is stored in the database (this is UTC time but without an identifier), which doesn't bother me, but with JASON Forward this UTC time is transferred with an identifier and this then causes external multiple conversion work, which could be avoided.

traccar timezone.png