Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript time independent of client PC's time

Tags:

javascript

Is there a way to get the current UTC time without relying on the time and timezone of the client's pc? I am not allowed to use PHP or anything from the server side for this (Using a hosted service and they only allow changing of HTML and addition of JavaScript. Not allowed to change PHP on the server.). Must be only done from the client side via JavaScript.

Thanks in advance for any suggestions / solutions.

If my question is not clear, please let me know what else would make it clearer and I will add those details.

Best regards, Tony.

like image 773
gt10001 Avatar asked Nov 27 '25 00:11

gt10001


1 Answers

No, JavaScript can only give you the client time, or a value provided by the server (e.g. a special hidden utcTime input element). You have ruled out the latter.

However, for dynamic pages, document.lastModified may be a close approximation to the current server time. This is based on the Last-Modified header.

like image 186
Matthew Flaschen Avatar answered Nov 29 '25 13:11

Matthew Flaschen