Skip to content

Instantly share code, notes, and snippets.

@bluekeys
Last active December 10, 2015 11:48
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 bluekeys/4429792 to your computer and use it in GitHub Desktop.
Save bluekeys/4429792 to your computer and use it in GitHub Desktop.
My preferred javascript timestamp - an implementation of an ISO 8601 wannabe
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