Timezone Wrong from Traccar API

wilsongome 8 years ago

Hi, I have started to use the Traccar API and I have seen that de timezone from that is wrong. The date is correct in the database (MySQL) and in the site too, but when I call the API it is showing a (+3:00) timezone. How can I fix this problem?

Thanks!

Anton Tananaev 8 years ago

API returns you server time zone. If time is not correct it means that either device sends wrong time or something is misconfigured.

wilsongome 8 years ago

Humm... It's so strange, see the register please:

The small diference is the time that it takes to get each information.

Server Data (Ubuntu)
Tue May 15 17:19:01 BRT 2018

MySQL data

# id, name, uniqueid, lastupdate, positionid, groupid, attributes, phone, model, contact, category, disabled
'21', 'Celular Wilson', '213489', '2018-05-15 17:14:44', '3474728', '10', '{\"speedLimit\":50}', '', '', '', 'person', '0'

API result

{"id":21,"attributes":{"speedLimit":50},"groupId":10,"name":"Celular Wilson","uniqueId":"213489","status":"online","lastUpdate":"2018-05-15T20:14:43.652+0000","positionId":3474728,"geofenceIds":[6,8],"phone":"","model":"","contact":"","category":"person","disabled":false}
Anton Tananaev 8 years ago

Well, everything is correct. BRT is 3 hours behind UTC.

wilsongome 8 years ago

Ok, in that case should I handle the timezone on the client that is calling the api, doing the conversion?

Anton Tananaev 8 years ago

You don't need to do any conversion. Traccar sends correct ISO time with timezone.

wilsongome 8 years ago

Desculpe, não entendi. Na web exibe o horário certo, no app também, somente a API exibe o horário + 3:00 e isso é correto? Eu quero obter 17:00, a API me retorna 20:00, se eu não converter exibirá 20:00 em minha aplicação, pois é o que está vindo da API. Desculpe minha ignorância por favor.

wilsongome 8 years ago

Sorry, I do not understand. On the web it displays the right time, in the app too, only the API displays the time + 3:00 and this is correct? I want to get 17:00, the API returns me 20:00, if I do not convert it will show 20:00 on my application, because that's what's coming from the API. Sorry for my ignorance, please.

Anton Tananaev 8 years ago

Traccar API returns full ISO date format with timezone offset:

https://en.wikipedia.org/wiki/ISO_8601

Any modern programming language can handle it without need for any conversion.

wilsongome 8 years ago

Now it's turned clear. Thanks!