Skip to content

Instantly share code, notes, and snippets.

@hxgdzyuyi
Created November 9, 2015 15:36
Show Gist options
  • Save hxgdzyuyi/ca20f381b48096588c62 to your computer and use it in GitHub Desktop.
Save hxgdzyuyi/ca20f381b48096588c62 to your computer and use it in GitHub Desktop.
define(function() {
if (Date.prototype.toISOString) {
return function() {
return (new Date()).toISOString()
}
}
// modify from http://stackoverflow.com/a/8563517
function pad(number) {
var r = String(number)
if ( r.length === 1 ) {
r = '0' + r
}
return r
}
return function() {
var date = new Date()
return date.getUTCFullYear()
+ '-' + pad( date.getUTCMonth() + 1 )
+ '-' + pad( date.getUTCDate() )
+ 'T' + pad( date.getUTCHours() )
+ ':' + pad( date.getUTCMinutes() )
+ ':' + pad( date.getUTCSeconds() )
+ '.' + String( (date.getUTCMilliseconds()/1000).toFixed(3) )
.slice( 2, 5 )
+ 'Z'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment