The Date.parse method

The Date.parse method returns the number of milliseconds before the date passed in the parameter as an ISO format string. ISO format looks like this: 'YYYY-MM-DDTHH:mm:ss.sssZ', where: 'YYYY-MM-DD' - date; 'T' - separator; 'HH:mm:ss.sss' - time; 'Z' - time zone. It is not necessary to send the full format, just send 'YYYY-MM-DD' or just YYYY.

Syntax

javascriptDate.parse('YYYY-MM-DDTHH:mm:ss.sssZ');

Example

Let's use the Date.parse method to find out how many milliseconds have passed from 1 January 1970 to 11/16/2016, 12:59:59:

javascriptlet res = Date.parse('2016-11-16T12:59:59');
console.log(res);

The code execution result:

javascript1479290399000

Example

And now let's output the number of milliseconds, specifying only the year:

javascriptlet res = Date.parse('2016');
console.log(res);

The code execution result:

javascript1451606400000

Example

Let's set the Date.parse method parameter to wrong date:

javascriptlet res = Date.parse('20162016');
console.log(res);

The code execution result:

javascriptNaN

See also

  • the getTime method
    that also obtains the timestamp
  • the Date.now method
    that also obtains the timestamp