Skip to content

Instantly share code, notes, and snippets.

@icodejs
Created January 18, 2013 16:52
Show Gist options
  • Save icodejs/4566009 to your computer and use it in GitHub Desktop.
Save icodejs/4566009 to your computer and use it in GitHub Desktop.
Get UTC time
function _getUtcTime () {
var
d = date,
i = 0,
arr,
t;
d = d || new Date(); // default to now
arr = [
d.getUTCFullYear(),
d.getUTCMonth(),
d.getUTCDate(),
d.getUTCHours(),
d.getUTCMinutes(),
d.getUTCSeconds()
],
arr[1] += 1; // incrememt month by 1
while (i++ < 7) {
t = arr[i];
if (t < 10) {
arr[i] = '0' + t; // pad with 0
}
}
return arr.splice(0, 3).join('-') + 'T' + arr.join(':');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment