Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ISO 8601 is often used to pass time/date info between systems</p> <p>It allows yyyy-mm-dd alone for midnight GMT of that date,</p> <p>or the date followed by 'T' and time data,</p> <p>with optional seconds and milliseconds (after ',').</p> <p>yyyy-mm-ddThh:mm</p> <p>yyyy-mm-ddThh:mm:ss.xxx</p> <p>You finish with either Z for greenwich time, nothing, also for Greenwich time, or a + or - and the hh:mm offset from GMT.</p> <p>You can make your own method- this passes back the local Date, using the built in method if it is available- only firefox, so far.</p> <pre><code>Date.ISO= function(s){ var D= new Date(s); if(D.getDate()) return D; var M= [], min= 0, Rx= /([\d:]+)(\.\d+)?(Z|(([+\-])(\d\d):(\d\d))?)?$/; D= s.substring(0, 10).split("-"); if(s.length&gt; 11){ M= s.substring(11).match(Rx) || []; if(M[1]) D= D.concat(M[1].split(":")); if(M[2]) D.push(Math.round(M[2]*1000)); } D= D.map(function(itm){return parseInt(itm, 10);}); D[1]-= 1; while(D.length &lt; 7) D.push(0); if(M[4]){ min= parseInt(M[6])*60 + parseInt(M[7], 10); if(M[5]== "+") min*= -1; } D= new Date(Date.UTC.apply(Date, D)); if(!D.getDate()) throw "Bad Date- " + s; if(min) D.setMinutes(D.getMinutes()+ min); return D; } </code></pre> <p>//tests</p> <pre><code>var s= "2010-06-09T19:20:30+01:00"; alert(Date.ISO(s).toUTCString()); </code></pre> <p>/* value: (String) Safari 5.0: Wed, 09 Jun 2010 18:20:30 GMT</p> <p>MSIE 8.0: Wed, 9 Jun 2010 18:20:30 UTC</p> <p>Chrome 5.0.375.70: Wed, 09 Jun 2010 18:20:30 GMT</p> <p>Opera 10.53: Wed, 09 Jun 2010 18:20:30 GMT</p> <p>Firefox 3.6.3: Wed, 09 Jun 2010 18:20:30 GMT */</p> <p>Note- To work in IE (and older browsers) you'll need to fake the array map method-</p> <pre><code>if(![].map){ Array.prototype.map= function(fun, scope){ var L= this.length, A= Array(this.length), i= 0, val; if(typeof fun== 'function'){ while(i&lt; L){ if(i in this){ A[i]= fun.call(scope, this[i], i, this); } ++i; } return A; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload