Skip to content

Instantly share code, notes, and snippets.

@freekrai
Created May 2, 2017 14:37
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 freekrai/3d109f0756a9fe9cb45ed153e0f252bd to your computer and use it in GitHub Desktop.
Save freekrai/3d109f0756a9fe9cb45ed153e0f252bd to your computer and use it in GitHub Desktop.
js unixTime
// return the date as a unix time timestamp.
Date.prototype.getUnixTime = function() { return this.getTime()/1000|0 };
if(!Date.now) Date.now = function() { return new Date(); }
Date.time = function() { return Date.now().getUnixTime(); }
var currentUnixTime = Date.time();
currentUnixTime = Date.now().getUnixTime(); // same as above
// Parse a date and get it as Unix time
var parsedUnixTime = new Date('Mon, 25 Dec 2016 13:30:00 GMT').getUnixTime();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment