The JavaScript Date object represents a point in time based on several milliseconds since the Age (January 1, 1970 at midnight UTC). Naturally, new Date uses the clock of the environment in which it starts to get this value. So if it is in the browser on my machine and my clock is not set correctly, it will use my device incorrectly. *
Then they have two sets of functions that you can use to obtain information about this point in time: a local time zone function, such as getHours , getMonth , etc., and UTC functions, such as getUTCHours , getUTCMonth , etc. Local time zone functions work in the time zone of the environment. Naturally, UTC functions work in UTC.
So, let's say someone is in California on March 3, 2017 and does this at 11:30 in the morning exactly at the time:
var dt = new Date(); console.log(dt.getHours());
The base value of the object is 1488569400000, but the functions of the local time zone tell us that 11 hours and the functions of UTC tell us about it at 7 hours.
* (Although, as James Thorpe points out , the specification is a little vague about this, simply saying that it uses "current time", so theoretically the environment can decide whether to use a time server other than the local machine, but ...)
source share