RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find ISO8601 Date Parser v2
Expression
^(\d{4})(?:-([0]\d|[1][0-2]))(?:-([0-2]\d|[3][01]))(?:T([01]\d|2[0-3]))(?::([0-5]\d))(?::([0-5]\d)(?:\.(\d{1,7}?)|)|)(Z|([+-])([01]\d|2[0-3])(?::([0-5]\d)))$
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); } }
Matches
2013-12-01T04:33Z, 2013-12-01T04:33:12.234Z, 2013-12-01T23:12-07:00
Non-Matches
2013, 2013-12, 2013-12-01, 2013-99-99T99:99Z
Author Rating: The rating for this expression. Charles Forsyth
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2018, RegexAdvice.com | ASP.NET Tutorials