Convert ISO 8601 time date into plain English

后端 未结 3 1085
孤街浪徒
孤街浪徒 2020-12-16 03:56

How can I manipulate a date time in the format below (I believe it is ISO 8601 format) with JavaScript?

2010-01-13T18:31:16Z

I\'d like to output as dd/mm/yyy

3条回答
  •  旧巷少年郎
    2020-12-16 04:36

    You can easily change the format with an regex, e.g.

    return datestring.replace(/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/, "$3/$2/$1 $4:$5:$6");
    

    or, you parse the string to a Date object, and extract the single values (or many more, like the weekday etc):

    var date = new Date(datestring); // parses ISO 8601
    return date.getDate()+"/"+(date.getMonth()+1)+"/"+date.getFullYear()+" "+…
    

提交回复
热议问题