Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why new Date().getTime() returns too much "0" in javascript

I'm trying to get a timestamp from a date in javascript but new Date(2013, 03, 17).getTime() return 1366149600000 which is wrong (1981-2-2 23:11:12). If I remove the three last zeros, I get the good date.

Where the problem come from ?

like image 895
thomas-hiron Avatar asked Apr 17 '13 17:04

thomas-hiron


2 Answers

it returns milliseconds, unix timestamp are in seconds hence your need to remove the last 3 digits

like image 150
Damien Legros Avatar answered Nov 03 '22 00:11

Damien Legros


As per Damien's answer, you will get milliseconds so basically you have to divide the .getTime() result per 1000

getTime() / 1000 => good unixtimestamp

like image 43
Gianfranco Reppucci Avatar answered Nov 03 '22 01:11

Gianfranco Reppucci