The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Get An Epoch Timestamp In JavaScript

TODO: Pull subtitle into page object code_start_default_section code_end_default_section

TODO: Add stuff about `.parse()``

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

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/
-- javascript

const epochTime = Date.now()

-- /code

-- results/

1642449085896

-- /results

-- p

Epoch in milliseconds for a specific time are obtained with:

-- code/
-- javascript

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

-- /code

-- results/

// Outputs:
1445394480000

-- /results

-- p

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

-- code/
-- javascript


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

-- /code

-- p

-- h2

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/
-- javascript

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

-- /code

-- p

And this for a specific datetime:

-- code/
-- javascript

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

-- /code

-- p

TODO: Add stuff about `.parse()``


-- categories
-- JavaScript

-- metadata
-- date: 2022-01-17 13:53:25
-- id: 23pz2bli
-- status: published
-- type: post
-- SCRUBBED_NEO: false
-- site: aws