I was wondering if there is any API/way/site/link that provides the correct time?
Not the servers datetime or the clients datetime. I'm using datetime to count down on my gaming site for when it is the user's time to make a play. Users come from all over the world, so using their client time would not match if it's from the US to Europe.
Then normally I would use the servers time, but somehow it skips 1.2 hours sometimes? I would like to make sure that everbody makes a timestamp from the same source and that source is always correct!
Any ideas?
First, you should use UTC in the client and in the server code to avoid timezone problems.
Further I understand your problem in a way that it is not so important that the time is exactly (nanoseconds) correct, it is more important, that the time will be the SAME on server and clients.
So you'll need a unique source for that UTC time for both client and servers. This should be definitely your server. I could suggest using your server as NTP server for the clients. But assuming your are in a web environment this sounds not practicable.
So I would suggest to add a timestamp - UTC time - to every message from server. Clients will have to use this timestamp as reference. Additonaly could make clients update their time periodically by calling your server.
Using your server's time is fine, just make sure to get the Timezones correctly:
$now = new DateTime;
$now->setTimeZone(new DateTimeZone("Europe/London"));
Now, $now
would contain a DateTime object, with the correct time in London.
PHP does a great job with Daylight saving, and weird custom time events.