javascript - RFC 2822 and ISO 8601 date format regex -
in javascript there date.parse()
method, parses string representing rfc 2822 or iso 8601 date (see mdn). among tons of various sources on web, reliable , comprehensive regular expressions able match date formats (separately)?
update: if there no reasonable way comprehensive regex match these formats entirely, @ least patterns these particular rfc , iso formats, date.parse()
method accepts , understands correctly.
i think answer there no single regex(or rather bad idea approach tricky , difficult) match formats listed in rfc 2822 or iso 8601. not safe , approach having regex formats. however, if have specific format yes can go regex.
you may check date.js , moment.js
edit:
the same mdn says:
parameters
datestring
string representing rfc822 or iso 8601 date.description
the parse method takes date string (such "dec 25, 1995") , returns number of milliseconds since january 1, 1970, 00:00:00 utc. local time zone used interpret arguments not contain time zone information. function useful setting date values based on string values, example in conjunction settime method , date object.
given string representing time, parse returns time value. it accepts rfc822 / ietf date syntax (rfc 1123 section 5.2.14 , elsewhere), e.g. "mon, 25 dec 1995 13:30:00 gmt". understands continental time-zone abbreviations, general use, use time-zone offset, example, "mon, 25 dec 1995 13:30:00 gmt+0430" (4 hours, 30 minutes east of greenwich meridian). if not specify time zone, local time zone assumed. gmt , utc considered equivalent.
alternatively, date/time string may in iso 8601 format. starting javascript 1.8.5 / firefox 4, subset of iso 8601 supported. for example, "2011-10-10" (just date) or "2011-10-10t14:48:00 (date , time) can passed , parsed. timezones in iso dates not yet supported, e.g. "2011-10-10t14:48:00+0200" (with timezone) not give intended result yet.
from here
this format includes date-only forms:
- yyyy
- yyyy-mm
- yyyy-mm-dd
...
all numbers must base 10. if mm or dd fields absent “01” used value. if mm or ss fields absent “00” used value , value of absent sss file “000”. value of absent time zone offset “z”.
also check this
Comments
Post a Comment