Examples of calling a cross-browser, Javascript shim - toISOString - which converts a Date object into an ISO 8601 formatted string - 'YYYY-MM-DDTHH:mm:ss.sssZ' - with a fallback for when the function doesn't exist (e.g. IE 8 or less).
var o = document.getElementById('output'),
dateToConvert;
// Date created with today's date and time according to local time
dateToConvert = new Date;
o.innerHTML += '1. ' + dateToConvert.toISOString() + '<br>';
// Date created with all parameters - y,m,d,h,m,s,ms
dateToConvert = new Date(2008,8,10,12,12,13,14);
o.innerHTML += '2. ' + dateToConvert.toISOString() + '<br>';
// Date created with minumum parameters - y,m,d
dateToConvert = new Date(2014,1,28);
o.innerHTML += '3. ' + dateToConvert.toISOString() + '<br>';
// Date created with ms since 1 January 1970 00:00:00 UTC (Unix Epoch)
dateToConvert = new Date(10000000);
o.innerHTML += '4. ' + dateToConvert.toISOString() + '<br>';
// Date created with String value representing a date
dateToConvert = new Date('2009/07/13 12:34:56');
o.innerHTML += '5. ' + dateToConvert.toISOString() + '<br>';
// Invalid date - will error, no output
dateToConvert = 'zzzzzz';
o.innerHTML += '6. ' + dateToConvert.toISOString() + '<br>';
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.