Parse() function is used to parse a string having commonly used formats to DateTime object. If you want to pass a non-standard or more complicated string, then use the from_format() function.
However, if you want the library to fall back on the dateutil parser, you have to pass strict=False.
The library natively supports the RFC 3339 format, most ISO 8601 formats and some other common formats.Like below
RFC 3339
STRING | OUTPUT |
---|---|
1996-12-19T16:39:57-08:00 | 1996-12-19T16:39:57-08:00 |
1990-12-31T23:59:59Z | 1990-12-31T23:59:59+00:00 |
STRING | OUTPUT |
---|---|
20161001T143028+0530 | 2016-10-01T14:30:28+05:30 |
20161001T14 | 2016-10-01T14:00:00+00:00 |
STRING | OUTPUT |
---|---|
2012 | 2012-01-01T00:00:00+00:00 |
2012-05-03 | 2012-05-03T00:00:00+00:00 |
20120503 | 2012-05-03T00:00:00+00:00 |
2012-05 | 2012-05-01T00:00:00+00:00 |
STRING | OUTPUT |
---|---|
2012-007 | 2012-01-07T00:00:00+00:00 |
2012007 | 2012-01-07T00:00:00+00:00 |
STRING | OUTPUT |
---|---|
2012-W05 | 2012-01-30T00:00:00+00:00 |
2012W05 | 2012-01-30T00:00:00+00:00 |
2012-W05-5 | 2012-02-03T00:00:00+00:00 |
2012W055 | 2012-02-03T00:00:00+00:00 |
When passing only time information the date will default to today.
STRING | OUTPUT |
---|---|
00:00 | 2016-12-17T00:00:00+00:00 |
12:04:23 | 2016-12-17T12:04:23+00:00 |
120423 | 2016-12-17T12:04:23+00:00 |
12:04:23.45 | 2016-12-17T12:04:23.450000+00:00 |
STRING | OUTPUT |
---|---|
2007-03-01T13:00:00Z/2008-05-11T15:30:00Z | 2007-03-01T13:00:00+00:00 -> 2008-05-11T15:30:00+00:00 |
2008-05-11T15:30:00Z/P1Y2M10DT2H30M | 2008-05-11T15:30:00+00:00 -> 2009-07-21T18:00:00+00:00 |
P1Y2M10DT2H30M/2008-05-11T15:30:00Z | 2007-03-01T13:00:00+00:00 -> 2008-05-11T15:30:00+00:00 |
Comments