Primary
dateutil.parser.parse() ⚬|Documentation|1st|20251021210445-00-⌔
parser — dateutil 3.9.0 documentation#dateutil.parser.parse
parser.parse(parserinfo=None, ﹡﹡kwargs)Parse a string in one of the supported formats, using the
parserinfoparameters.Parameters:
- timestr – A string containing a date/time stamp.
- parserinfo – A
parserinfoobject containing parameters for the parser. IfNone, the default arguments to theparserinfoconstructor are used.The
﹡﹡kwargsparameter takes the following keyword arguments:Parameters:
- default – The default datetime object, if this is a datetime object and not
None, elements specified intimestrreplace elements in the default object.- ignoretz – If set
True, time zones in parsed strings are ignored and a naivedatetimeobject is returned.- tzinfos – Additional time zone names/aliases which may be present in the string. This argument maps time zone names (and optionally offsets from those time zones) to time zones. This parameter can be a dictionary with timezone aliases mapping time zone names to time zones or a function taking two parameters (
tznameandtzoffset) and returning a time zone. The timezones to which the names are mapped can be an integer offset from UTC in seconds or atzinfoobject. This parameter is ignored ifignoretzis set.>>> from dateutil.parser import parse >>> from dateutil.tz import gettz >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")} >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos) datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200)) >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos) datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago'))
- dayfirst – Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (
True) or month (False). Ifyearfirstis set toTrue, this distinguishes between YDM and YMD. If set toNone, this value is retrieved from the currentparserinfoobject (which itself defaults toFalse).- yearfirst – Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the year. If
True, the first number is taken to be the year, otherwise the last number is taken to be the year. If this is set toNone, the value is retrieved from the currentparserinfoobject (which itself defaults toFalse).- fuzzy – Whether to allow fuzzy parsing, allowing for string like “Today is January 1, 2047 at 8:21:00AM”.
- fuzzy_with_tokens – If
True,fuzzyis automatically set to True, and the parser will return a tuple where the first element is the parseddatetime.datetimedatetimestamp and the second element is a tuple containing the portions of the string which were ignored:>>> from dateutil.parser import parse >>> parse("Today is January 1, 2047 at 8:21:00AM", fuzzy_with_tokens=True) (datetime.datetime(2047, 1, 1, 8, 21), (u'Today is ', u' ', u'at '))Returns:
Returns a
datetime.datetimeobject or, if thefuzzy_with_tokensoption isTrue, returns a tuple, the first element being adatetime.datetimeobject, the second a tuple containing the fuzzy tokens.Raises:
- ParserError – Raised for invalid or unknown string formats, if the provided
tzinfois not in a valid format, or if an invalid date would be created.- OverflowError – Raised if the parsed date exceeds the largest valid C integer on your system.
Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •