1

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"

1 Answers1

4

Use this code to get the timestamp.

targetDate.getTime()
Mantu Nigam
  • 3,690
  • 7
  • 24
  • 41
  • `targetDate.getTime()` is converting my date into timestamp but it's `1494135757264` of 13 Digit, while the timestamp which stores in my DB is `1496679262` of 10 digit. whats's that last 3 digit stand for –  Jun 06 '17 at 05:49
  • Please visit this link may provide a solution to your problem. https://stackoverflow.com/questions/13242828/javascript-gettime-to-10-digits-only/13242834 – Mantu Nigam Jun 06 '17 at 06:26