ASHISH KARN
ASHISH KARN

Reputation: 131

Does Date.now() return different value for different timezones?

The definition for Date.now() is not clear for me. As per definition "The Date. now() is an inbuilt function in JavaScript which returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.". So, does it mean that it will give same value for Date.now() in all timezone?
The current date and time, picked for calculation, is my local timezone or UTC ? I have same query for java.util.Date getTime() method.

Upvotes: 3

Views: 4001

Answers (1)

akuzminykh
akuzminykh

Reputation: 4723

Yes, Date.now() will give you the same UTC timestamp independent of your current timezone. Such a timestamp, rather a point in time, does not depend on timezones.

The Java equivalent new Date() gives you the exact same thing.

Check out Coordinated Universal Time (UTC) for more information.


FYI: Don't use new Date() in Java as it's a legacy class. Use Instant.now() that is from the new java.time API that is much more robust and has a nicer design.

Upvotes: 12

Related Questions