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;
'Т' - 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
Date.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:
let res = Date.parse('2016-11-16T12:59:59');
console.log(res);
The code execution result:
1479290399000
Example
And now let's output the number of milliseconds, specifying only the year:
let res = Date.parse('2016');
console.log(res);
The code execution result:
1451606400000
Example
Let's set the Date.parse method
parameter to wrong date:
let res = Date.parse('20162016');
console.log(res);
The code execution result:
NaN