Skip to content

Instantly share code, notes, and snippets.

@nefarioustim
Created April 11, 2011 09:12
Show Gist options
  • Save nefarioustim/913270 to your computer and use it in GitHub Desktop.
Save nefarioustim/913270 to your computer and use it in GitHub Desktop.
Prototype a method onto the Date object that returns a UTCDateTime string.
Date.prototype.getUTCDateTime = function() {
var zf = function(num) {
return ((num + 100) + '').substr(1);
};
return [
this.getUTCFullYear(),
'-',
zf(this.getUTCMonth() + 1),
'-',
zf(this.getUTCDate()),
'T',
zf(this.getUTCHours()),
':',
zf(this.getUTCMinutes()),
':',
zf(this.getUTCSeconds()),
'Z'
].join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment