JavaScript's getTime() returns "the number of milliseconds since 1 January 1970 00:00:00 UTC".
Can I rely on this being similar across different machines? I don't need it to be accurate to the millisecond, just to a few seconds.
Or do I need to use an external time service API, as in this question?
Where does JavaScript get the current time from - is it dependent on the machine's clock?
The getTime() method returns the number of milliseconds since the ECMAScript epoch. You can use this method to help assign a date and time to another Date object. This method is functionally equivalent to the valueOf() method.
In JavaScript, we can compare two dates by converting them into numeric values to correspond to their time. First, we can convert the Date into a numeric value by using the getTime() function. By converting the given dates into numeric values we can directly compare them.
getTime() . The method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation. Calling the method from any time zone returns the same UTC timestamp.
JavaScript Date getTime() getTime() returns the number of milliseconds since January 1, 1970 00:00:00.
Can I rely on this being similar across different machines?
No.
Where does JavaScript get the current time from
The system datetime on which this javascript runs.
Or do I need to use an external time service API, as in this question?
You could use the server's time and send it to the client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With