Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date time to integer timestamp in javascript [duplicate]

Tags:

javascript

How do I convert this into timestamp

Datetime = 2014-07-14T09:34:47.000Z

Timestamp = ?

like image 750
Ajey Avatar asked Dec 09 '25 20:12

Ajey


2 Answers

var Datetime = "2014-07-14T09:34:47.000Z";
new Date(Datetime).getTime();

This will return the number of milliseconds since the epoch.

like image 54
Husman Avatar answered Dec 11 '25 09:12

Husman


Try this:

function getTimeStamp(dateStr) { //example: "2014-07-14T09:34:47"
  var s = new Date(dateStr); 
  return s.getFullYear()*10000000000 + (s.getMonth()+1)*100000000 + s.getDate()*1000000 + s.getHours()*10000 + s.getMinutes()*100 + s.getSeconds();
}

Note that you have to remove the milliseconds from your example.

like image 33
zarkobehar Avatar answered Dec 11 '25 10:12

zarkobehar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!