grippat Posted November 14, 2007 Share Posted November 14, 2007 How would I use JavaScript to get the current Unix timestamp? Link to comment Share on other sites More sharing options...
Ingolme Posted November 14, 2007 Share Posted November 14, 2007 You can try this:a = new Date()var d = Number(Date.UTC(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours(),a.getMinutes(),a.getSeconds(),0));d = d/1000;// d would be the Unix timestamp for this moment. Link to comment Share on other sites More sharing options...
Pollux Posted November 14, 2007 Share Posted November 14, 2007 A slightly shorter way to achieve the same thing would be: Math.floor(new Date().getTime()/1000) Link to comment Share on other sites More sharing options...
justsomeguy Posted November 14, 2007 Share Posted November 14, 2007 How about:new Date().valueOf() Link to comment Share on other sites More sharing options...
Pollux Posted November 14, 2007 Share Posted November 14, 2007 valueOf() uses the getTime() implementation internally which means that as with getTime() it returns a timestamp which is ms since the epoch, however the unix timestamp is seconds since the epoch. So we need to divide by 1000 and then perform a round to get an integer. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.