1

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.

deceze
  • 510,633
  • 85
  • 743
  • 889
Lucas
  • 16,930
  • 31
  • 110
  • 182
  • Can you explain a bit more clearly what it is you need to accomplish? – T.J. Crowder Feb 12 '13 at 10:48
  • [datetime.settimezone](http://php.net/manual/de/datetime.settimezone.php) – bitWorking Feb 12 '13 at 10:50
  • possible duplicate of [JavaScript NTP time](http://stackoverflow.com/questions/5522191/javascript-ntp-time) - You're wanting to sync possibly inaccurate clocks client-side, for which NTP is the right protocol. On top of that you need to do your timezone calculations. – deceze Feb 12 '13 at 10:54
  • Not a dup, and that link is bad because it claims NTP but really is just passing the time in json and not using the NTP protocol at all. – Matt Johnson-Pint Feb 12 '13 at 17:02

2 Answers2

1

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

Alfergon
  • 5,463
  • 6
  • 36
  • 56
davnis
  • 36
  • 1
0

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.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575