Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created January 4, 2014 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/8258933 to your computer and use it in GitHub Desktop.
Save joyrexus/8258933 to your computer and use it in GitHub Desktop.
Convert dates to milliseconds

We can convert numbers (representing time in milliseconds) to dates (and vice versa).

Create a new Date object:

now = new Date()        # Sat Jan 04 2014 12:39:41 GMT-0600 (CST)

Convert the Date object to an integer representing the number of milliseconds since UNIX epoch:

time = +now             # 1388860781079

Convert time in milliseconds back to a Date object:

date = new Date(time)   # Sat Jan 04 2014 12:39:41 GMT-0600 (CST)
# Convert between numbers (representing time in milliseconds) and dates
now = new Date() # Sat Jan 04 2014 12:39:41 GMT-0600 (CST)
time = +now # 1388860781079
date = new Date(time) # Sat Jan 04 2014 12:39:41 GMT-0600 (CST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment