Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A somewhat more robust way of parsing the dates would be:</p> <pre><code> var parser = XRegExp("^ (?&lt;prefix&gt; [^:;]+ ) # DTSTART/DTEND/DTSTAMP \n\ ((:|;TZID=(?&lt;tz&gt;[^:]+):)) # timezone \n\ (?&lt;year&gt; [0-9]{4} ) # year \n\ (?&lt;month&gt; [0-9]{2} ) # month \n\ (?&lt;day&gt; [0-9]{2} ) T # day \n\ (?&lt;hour&gt; [0-9]{2} ) # hour \n\ (?&lt;minute&gt; [0-9]{2} ) # minute \n\ (?&lt;second&gt; [0-9]{2} ) # second \n\ (?&lt;utc&gt; Z? ) # utc", "x"); parts = parser.exec (d); var od = new Date (parseInt (parts.year, 10), parseInt (parts.month, 10) - 1, parseInt (parts.day, 10), parseInt (parts.hour, 10), parseInt (parts.minute, 10), parseInt (parts.second, 10)); </code></pre> <p>This requires you to add an additional (tiny) dependency, <a href="http://xregexp.com/" rel="nofollow" title="XRegExp">XRegExp</a>, which might be a bit overkill depending on your further needs, but it allows for a clean, easy to read regexp parsing of the date format in .ics files. This also takes into account the time zone identifier, if the date is not UTC. I leave it to you to add proper handling of time zones as well as the use of the <code>prefix</code> part.</p> <p>The short answer (as noted by jessegavin) however, is that the <code>month</code>-parameter of the constructor expects a number between 0-11 (refer <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date" rel="nofollow">Mozilla Developer Network</a> for more information). However, <code>parseInt()</code> tries to parse leading zeros as <code>radix 8</code> (octal), so you should make sure to add <code>radix 10</code> too, that would be the second parameter to <code>parseInt(string [, radix])</code>.</p>
    singulars
    1. This table or related slice is empty.
    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. 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