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

前端 未结 4 443
离开以前
离开以前 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:14

    i suggest you use moment.js for this. In moment.js you can:

    var localTime = moment().format('YYYY-MM-DD'); // store localTime
    var proposedDate = localTime + "T00:00:00.000Z";
    

    now that you have the right format for a time, parse it if it's valid:

    var isValidDate = moment(proposedDate).isValid();
    // returns true if valid and false if it is not.
    

    and to get time parts you can do something like:

    var momentDate = moment(proposedDate)
    var hour = momentDate.hours();
    var minutes = momentDate.minutes();
    var seconds = momentDate.seconds();
    
    // or you can use `.format`:
    console.log(momentDate.format("YYYY-MM-DD hh:mm:ss A Z"));
    

    More info about momentjs http://momentjs.com/

提交回复
热议问题