Posts

Showing posts with the label 8601

ECMAScript ISO Date For Every Browser

One most than welcome new entry of ECMAScript 5 is the Date.prototype.toISOString function and ability for Date constructor to accept an ISO String and to generate a Date instance. This feature will make JSON Date instances import/export extremely fast and simple, but why should we wait ES5 release when we can have both features now? Full Specs ISO 8601 Parser Plus Unobtrusive toISOString Method We all do not like that much to extend native JavaScript constructors, so here I am with a proposal that will not touch the Date prototype: if(!Date.ISO)(function(){"use strict"; /** ES5 ISO Date Parser Plus toISOString Method * @author Andrea Giammarchi * @blog WebReflection * @version 2009-07-04T11:36:25.123Z * @compatibility Chrome, Firefox, IE 5+, Opera, Safari, WebKit, Others */ function ISO(s){ var m = /^(\d{4})(-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|((\+|-)(\d{2}):(\d{2}))))?)?)?$/.exec(s); if(m === null) thr...