Description |
Good for JavaScript. Parses an ISO8601 Date into separate Date() object parts, so you can set a Date object by passing in an ISO8601 string. NOTE: Will not match illegal dates such as the 32nd day of a month or the 61st minute of an hour, etc.
Use like this:
if (regexFull.test(dString)) {
matches = dString.toString().match(regexFull);
offset = 0;
date.setUTCDate(1);
date.setUTCFullYear(parseInt(matches[1],10));
date.setUTCMonth(parseInt(matches[2],10) - 1);
date.setUTCDate(parseInt(matches[3],10));
date.setUTCHours(parseInt(matches[4],10));
date.setUTCMinutes(parseInt(matches[5],10));
if (matches[6]) {
date.setUTCSeconds(parseInt(matches[6],10));
}
if (matches[7]) {
date.setUTCMilliseconds(parseInt(matches[7]));
}
if (matches[8] != 'Z') {
offset = (matches[10] * 60) + parseInt(matches[11],10);
offset *= ((matches[9] == '-') ? -1 : 1);
date.setTime(date.getTime() - offset * 60 * 1000);
}
} |