Static Timestamp Methods

The following three methods allow automatic adjustment to the local timezones. For instance, the same timestamp obtained from Date.now(), when passed into the Date() constructor, will cause different (local) times to be displayed at different locations around the globe. In other words, to allow your time display to adapt to different timezones, you should be storing and passing the timestamp instead of a date-and-time string.

Date.now()

Returns the numeric value corresponding to the current time - the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC, with leap seconds ignored.

Date.parse()

Parses a string representation of a date and returns the number of milliseconds since 1 January 1970, 00:00:00, UTC, with leap seconds ignored.

Note: Parsing of strings with Date.parse() is strongly discouraged due to browser differences and inconsistencies.

Date.UTC()

Accepts the same parameters as the longest form of the constructor (i.e. 2 to 7) and returns the number of milliseconds since 1 January 1970, 00:00:00 UTC, with leap seconds ignored.


RESETRUNFULL
<!DOCTYPE html><html><body><script>


   console.log(Date.now());  // 1500378966376
   console.log(Date.UTC(2017,07,18)); // 1503014400000      // Tue Jul 18 2017 19:56:06 GMT+0800
    console.log(Date(Date.now()));      // Fri Aug 18 2017 08:00:00 GMT+0800
   console.log(new Date(Date.UTC(2017,07,18)));

</script></body><html>