The module is not a Python built-in module that complements the ISO 8601 parsing for Python-converting common ISO 8601 date characters into a Python datetime object.
Installation
Install iso8601
Use
>>> Import iso8601
Example
>>> Import iso8601>>> iso8601.parse_date ("2007-01-25t12:00:00z") Datetime.datetime (2007, 1, 25, 12, 0, tzinfo=<iso8601. utc>) >>>
Format
You can parse either the full date + time pattern string, or just the string containing the date, both of which return a DateTime instance, but the returned time defaults to 0 and the returned day/month defaults to 1.
Date
- Yyyy-mm-dd
- YYYYMMDD
- YYYY-MM (Day defaults to 1)
- YYYY (month and day are defaulted to 1)
Time
- Hh:mm:ss.nn
- Hhmmss.nn
- HH:MM (second default is 0)
- HHMM (second default is 0)
- HH (both minute and second default to 0)
Time
- Default is UTC
- Z (UTC)
- +/-hh:mm
- +/-hhmm
- +/-hh
The difference from ISO 8601
- You can use spaces ("") instead of "T" to differentiate between dates and times
- The days and months below 10 are not identified by the number "0", for example (2 instead of 02).
- Time zone defaults to UTC
Api
Iso8601.parse_date (DateString, default_timezone=<iso8601. utc>)
Converts text in ISO 8601 format to a Python datetime object.
Parameters
- datestring-- The date string to parse, which can also contain time zone information
- Default_timezone --time zone information, a datetime tzinfo instance that is used when no time zone information is included in the parameter datestring . If set to None returns a simple datetime object.
return value
A Datetime.datetime instance
Abnormal
Exception iso8601. ParseError
Thrown parseerror when iso8601.parse_date () resolves an error or cannot construct a DateTime instance
python--pyiso8601