Last active
December 10, 2015 11:48
-
-
Save bluekeys/4429792 to your computer and use it in GitHub Desktop.
My preferred javascript timestamp - an implementation of an ISO 8601 wannabe
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
function Timestamp () { | |
var d, t, year, month, day, hour, minute, second, millisecond; | |
d = new Date(); | |
t = ''; | |
year = d.getFullYear(); | |
month = ('00' + (Number(d.getMonth()) + 1)).slice(-2); | |
day = ('00' + d.getDate()).slice(-2); | |
hour = ('00' + d.getHours()).slice(-2); | |
minute = ('00' + d.getMinutes()).slice(-2); | |
second = ('00' + d.getSeconds()).slice(-2); | |
millisecond = ('0000' + d.getMilliseconds()).slice(-4); | |
t = year + month + day + hour + minute + second + millisecond; | |
this.t = t; | |
}; | |
Timestamp.prototype.toString = function () { | |
return this.t; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment