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 `.now()` and `.getTime()` on a `Date`.
The epoch in millisecond for current time is available with:
Code
const epochTime = Date.
Results
1642449085896
Epoch in milliseconds for a specific time are obtained with:
Code
const backToTheFuture = .
Results
// Outputs:
1445394480000
To pull the epoch based timestamp back into a string do something like:
Code
const backToTheFutureString = .
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:
Code
const epochTimeUnix = Math.
And this for a specific datetime:
Code
const backToTheFutureUnix = Math.
TODO: Add stuff about `.parse()``