Skip to content

Instantly share code, notes, and snippets.

@fonji
Last active August 29, 2015 14:15
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 fonji/863b961ab83ae35c98fe to your computer and use it in GitHub Desktop.
Save fonji/863b961ab83ae35c98fe to your computer and use it in GitHub Desktop.
IE8 Date.prototype.toISOString support.js
// https://gist.github.com/fonji/863b961ab83ae35c98fe
// From http://stackoverflow.com/questions/12907862/ie8-date-compatibility-error
if ( !Date.prototype.toISOString ) {
(function() {
function pad(number) {
var r = String(number);
if ( r.length === 1 ) {
r = '0' + r;
}
return r;
}
Date.prototype.toISOString = function() {
return this.getUTCFullYear()
+ '-' + pad( this.getUTCMonth() + 1 )
+ '-' + pad( this.getUTCDate() )
+ 'T' + pad( this.getUTCHours() )
+ ':' + pad( this.getUTCMinutes() )
+ ':' + pad( this.getUTCSeconds() )
+ '.' + String( (this.getUTCMilliseconds()/1000).toFixed(3) ).slice( 2, 5 )
+ 'Z';
}
Date.prototype.toJSON = Date.prototype.toISOString;
}() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment