Monday 5 June 2017

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"



via Anand Deshmukh

No comments:

Post a Comment