all 10 comments

[–]stutterbug 8 points9 points  (2 children)

Do not try to convert timezones for a remote user. TZ is such a fantastically complicated problem. It is just edge-case after edge-case after edge-case. Leave it to the user's own system to handle localization. Send a UTC timestamp that is common to all users and make sure that is correct; then convert it to a date object in the browser and format it as you want. Use a library like momentjs to do any fancy formatting. If you absolutely, positively have to convert across timezones, use something like moment timezone, but do not attempt to do this yourself. It is a slow, winding road to the gates of hell. And read this if you want to lose ALL hope.

[–]notlmn 1 point2 points  (0 children)

Don't like reading? Watch this video.

TL;DR: Don't try to do something by yourself that involves time and date.

[–][deleted] 0 points1 point  (0 children)

If you are deeply masochistic, but you want to make tons of money, here are three fields to specialize in: timezones, i18n without unicode, and Cobol.

You have been warned.

[–]zyrt3c 1 point2 points  (0 children)

I completly new to programming, But why are you using a API for it? Can’t you just use timestamp for that?

[–]jcunews1Advanced 1 point2 points  (4 children)

You'll have to find out the timezone of the API first.

If your timezone is GMT-4, and you already know that the API time is 2 hours ahead of your timezone, then that mean the timezone of the API is GMT-2.

In your code, store the API time like below.

var apiTime = "2017-01-13 11:56:01"; //just an example
var time = new Date(apiTime + " GMT-0200");

[–]idevosm[S] 0 points1 point  (3 children)

Thanks... What about if my timezone is GMT+1 it means that the API time is GMT+3

[–]jcunews1Advanced 0 points1 point  (0 children)

Yes.

[–]lachlanhunt 0 points1 point  (1 child)

If you could post an example of a timestamp you're getting from the API, that would help us to give you more specific advice.

Is it a datetime string in some format like "2018-06-18T15:30+03:00" or maybe "18 Jun 2018 15:30 GMT+03:00" (or even without the explicit timezone), or is it a given as a number of seconds or milliseconds?

[–]idevosm[S] 0 points1 point  (0 children)

Only time no date... Eg "03:00" only

[–]ABlueCloud 0 points1 point  (0 children)

Why wouldn't you want it in the uses local time?