Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get An Epoch Timestamp In JavaScript

Epoch timestamps in JavaScript are the number of milliseconds that have elapsed since midnight on Jan. 1, 1970 UTC. I like using them because they are integers and are the same for any given time regardless of time zone.

They're also handy since they are what's returned from [TODO: Code shorthand span ] and [TODO: Code shorthand span ] on a ` Date ` .

The epoch in millisecond for current time is available with :

const epochTime = Date.now()
results start

Epoch in milliseconds for a specific time are obtained with :

const backToTheFuture = new Date('Oct 21, 2015 07:28:00 GMT+05:00').getTime()
results start

To pull the epoch based timestamp back into a string do something like :

const backToTheFutureString = new Date(backToTheFuture).toString()

Seconds Only

Some external tools provide epoch timestamps but they only go down to the second instead of the millisecond. If you need to coordinate with one of them, use this for the current time :

const epochTimeUnix = Math.round(Date.now() / 1000)

And this for a specific datetime :

const backToTheFutureUnix = Math.round(new Date('Oct 21, 2015 07:28:00 GMT+05:00').getTime() / 1000)

TODO : Add stuff about [TODO: Code shorthand span ]