Jump to content

JavaScript Unix timestamp?


Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...