Alex Rivera | Logout

Convert normal date to unix timestamp

Asked 2012-08-09T22:46:11.387
224

How can I convert normal date 2012.08.10 to unix timestamp in javascript?

Fiddle: http://jsfiddle.net/J2pWj/




I've seen many posts here that convert it in PHP, Ruby, etc... But I need to do this inside JS.

Edit
Report

2 Answers

437
Math.floor(new Date('2012.08.10').getTime() / 1000)

Check the JavaScript Date documentation.

answered 2012-08-09T22:53:01.513
2
var datestr = '2012.08.10';
var timestamp = (new Date(datestr.split(".").join("-")).getTime())/1000;
answered 2012-08-09T22:56:06.413

Your Answer