Zerium
Zerium

Reputation: 17333

How to get the time of specific timezone using javascript, but without being relevant to the current system time?

Now, before you mark this as a duplicate, please note that all the useful answers in the possible duplicate provide functions which work in relation to the current system time, which I cannot accept.

What I want, is that the current time in, say, for example, New York, be consistent to all users, no matter what their time settings are.

For example, I have two computers here, and one is 3 seconds behind the other, and this leaves an unacceptable gap, as my task involve pinpoint precision (slightly exaggerated, but you know what I mean).

How can I overcome this? Must I get the server time and somehow convert it? If so, I'm using PHP.

Upvotes: 1

Views: 3233

Answers (2)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241430

You need to use a timezone library to do this in JavaScript. See my answer here.

The scripts are small, but because they require the timezone database, it can get unwieldy for a client application. You're probably better off doing the conversion server side. Perhaps the pytz library will be useful to you.

Upvotes: 0

davnis
davnis

Reputation: 36

Hope to not be wrong but javascript is loaded on user machine, not on the server so you will allway get the visitor date/time using javascript. you can use php to get the date/time because is loaded on the server and pass the dates to javascript.

Hope this help

Upvotes: 1

Related Questions