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

前端 未结 4 457
离开以前
离开以前 2020-12-12 15:03

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

 T00:00:00.000Z

And how to parse it?

4条回答
  •  天命终不由人
    2020-12-12 15:20

    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());
    

提交回复
热议问题