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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find w3c correct datetime pattern with leapyear support
Expression
^[-]?((1[6789]|[2-9][0-9])[0-9]{2}-(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))T([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])([Z]|\.[0-9]{4}|[-|\+]([0-1][0-9]|2[0-3]):([0-5][0-9]))?$|^[-]?((1[6789]|[2-9][0-9])[0-9]{2}-(0[469]|11)-(0[1-9]|[12][0-9]|30))T([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])([Z]|\.[0-9]{4}|[-|\+]([0-1][0-9]|2[0-3]):([0-5][0-9]))?$|^[-]?((16|[248][048]|[3579][26])00)|(1[6789]|[2-9][0-9])(0[48]|[13579][26]|[2468][048])-02-(0[1-9]|1[0-9]|2[0-9])T([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])([Z]|\.[0-9]{4}|[-|\+]([0-1][0-9]|2[0-3]):([0-5][0-9]))?$|^[-]?(1[6789]|[2-9][0-9])[0-9]{2}-02-(0[1-9]|1[0-9]|2[0-8])T([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])([Z]|\.[0-9]{4}|[-|\+]([0-1][0-9]|2[0-3]):([0-5][0-9]))?$
Description
This pattern matches valid w3c compatible datetime values from 1600 to 9999 in the form of [-]YYYY-MM-DDTHH:MM:SS[.ssss|[[+|-][HH:MM]][Z] also takes into account leap years.
Matches
2007-11-02T18:00:00.1234 | 2000-02-29T12:00:12+03:00
Non-Matches
2005-01-20 | 23:00:00
Author Rating: Not yet rated. Koen de Boeve
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

Title: Pattern:yyyy-MM-ddTHH:mm:ss.fffZ
Name: Gubbala pallavi devi
Date: 11/30/2020 9:57:23 AM
Comment:
Can someone please help me with the below format yyyy-MM-ddTHH:mm:ss.fffZ (2020-08-13T16:01:34.123Z)


Title: a little bit closer :-)
Name: Koen de Boeve
Date: 11/5/2007 6:36:36 PM
Comment:
Yep, same problem as the previous one. think it is fixed now.


Title: Close but not quite
Name: Michael Ash
Date: 11/5/2007 10:52:04 AM
Comment:
The leap year check is incomplete. Your regex will match 2100-02-29T18:00:00.1234 which incorrect. 2100 is not a leap year. Also the way you have constructed the leap year check allows it to match outside of the stated boundary 1100-02-29T18:00:00.1234 also matches.


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