简体   繁体   中英

How to convert string timestamp to date using javascript

I created some funtion but how to convert string timestamp to date format for the given variabe.

var data="/Date(1424853425207)/";
data=data.parse(data);
consoe.log(data);

But enabe show the date for the above variable

You can fetch the timestamp using regex and then cast to a number so it can be used to create a new instance of Date :

var data = "/Date(1424853425207)/";
var timestamp = +data.replace(/\/Date\((.*?)\)\//g, '$1');
var date = new Date(timestamp);
console.log(date); // Wed Feb 25 2015 09:37:05 GMT+0100

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