简体   繁体   中英

How to convert Date into Timestamp

I want to convert date into timestamp

I have two different format of date Wed May 31 2017 15:33:47 GMT+0530 (India Standard Time) and 2017-05-31T10:03:47.592Z . I want to convert it into timestamp like 1379426880000 .

This is my code.

var noOfDays = 5;
var targetDate = new Date();

targetDate.setDate(targetDate.getDate() - noOfDays);
console.log("targetDate date is " + targetDate); //Wed May 31 2017 15:33:47 GMT+0530 (India Standard Time)
console.log(JSON.stringify(targetDate)); // "2017-05-31T10:03:47.592Z"

使用此代码获取时间戳。

targetDate.getTime()

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