What does this format means T00:00:00.000Z?

Ali Akram picture Ali Akram · Mar 9, 2015 · Viewed 246.2k times · Source

Can someone, please, explain this type of format in javascript

 T00:00:00.000Z

And how to parse it?

Answer

nanndoj picture nanndoj · Mar 9, 2015

It's a part of ISO-8601 date representation. It's incomplete because a complete date representation in this pattern should also contains the date:

2015-03-04T00:00:00.000Z //Complete ISO-8601 date

If you try to parse this date as it is you will receive an Invalid Date error:

new Date('T00:00:00.000Z'); // Invalid Date

So, I guess the way to parse a timestamp in this format is to concat with any date

new Date('2015-03-04T00:00:00.000Z'); // Valid Date

Then you can extract only the part you want (timestamp part)

var d = new Date('2015-03-04T00:00:00.000Z');
console.log(d.getUTCHours()); // Hours
console.log(d.getUTCMinutes());
console.log(d.getUTCSeconds());