Created
May 2, 2017 14:37
-
-
Save freekrai/3d109f0756a9fe9cb45ed153e0f252bd to your computer and use it in GitHub Desktop.
js unixTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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