简体   繁体   中英

Easy way to convert a timestamp to a human readable date

I have the following timestamp: 2016-03-29T14:14:43.000Z . Is there any easy way to use JavaScript to make it look something like the following: Mar 29, 2016 2:14p ? I tried using Date.parse() but it didn't seem to do anything.

{{yourValue| date:"MMM d, yyyy h:ma"}}

var ts = "2016-03-29T14:14:43.000Z";
var date = new Date(ts);
console.log(date);  // Displays Tue Mar 29 2016 16:14:43 GMT+0200 (Romance Summer Time)

Is that what you need ?

var ds = date.toUTCString();
console.log(ds.substr(0,24)); // Displays Tue Mar 29 2016 16:14:43

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM