Parse the date/time string into a :class:`datetime.datetime` object. :param timestr: Any date/time string using the supported formats. :param default: The default datetime object, if this is a datetime object and not ``None``, elements s
(self, timestr, default=None,
ignoretz=False, tzinfos=None, **kwargs)
| 575 | self.info = info or parserinfo() |
| 576 | |
| 577 | def parse(self, timestr, default=None, |
| 578 | ignoretz=False, tzinfos=None, **kwargs): |
| 579 | """ |
| 580 | Parse the date/time string into a :class:`datetime.datetime` object. |
| 581 | |
| 582 | :param timestr: |
| 583 | Any date/time string using the supported formats. |
| 584 | |
| 585 | :param default: |
| 586 | The default datetime object, if this is a datetime object and not |
| 587 | ``None``, elements specified in ``timestr`` replace elements in the |
| 588 | default object. |
| 589 | |
| 590 | :param ignoretz: |
| 591 | If set ``True``, time zones in parsed strings are ignored and a |
| 592 | naive :class:`datetime.datetime` object is returned. |
| 593 | |
| 594 | :param tzinfos: |
| 595 | Additional time zone names / aliases which may be present in the |
| 596 | string. This argument maps time zone names (and optionally offsets |
| 597 | from those time zones) to time zones. This parameter can be a |
| 598 | dictionary with timezone aliases mapping time zone names to time |
| 599 | zones or a function taking two parameters (``tzname`` and |
| 600 | ``tzoffset``) and returning a time zone. |
| 601 | |
| 602 | The timezones to which the names are mapped can be an integer |
| 603 | offset from UTC in seconds or a :class:`tzinfo` object. |
| 604 | |
| 605 | .. doctest:: |
| 606 | :options: +NORMALIZE_WHITESPACE |
| 607 | |
| 608 | >>> from dateutil.parser import parse |
| 609 | >>> from dateutil.tz import gettz |
| 610 | >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")} |
| 611 | >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos) |
| 612 | datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200)) |
| 613 | >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos) |
| 614 | datetime.datetime(2012, 1, 19, 17, 21, |
| 615 | tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago')) |
| 616 | |
| 617 | This parameter is ignored if ``ignoretz`` is set. |
| 618 | |
| 619 | :param \\*\\*kwargs: |
| 620 | Keyword arguments as passed to ``_parse()``. |
| 621 | |
| 622 | :return: |
| 623 | Returns a :class:`datetime.datetime` object or, if the |
| 624 | ``fuzzy_with_tokens`` option is ``True``, returns a tuple, the |
| 625 | first element being a :class:`datetime.datetime` object, the second |
| 626 | a tuple containing the fuzzy tokens. |
| 627 | |
| 628 | :raises ValueError: |
| 629 | Raised for invalid or unknown string format, if the provided |
| 630 | :class:`tzinfo` is not in a valid format, or if an invalid date |
| 631 | would be created. |
| 632 | |
| 633 | :raises TypeError: |
| 634 | Raised for non-string or character stream input. |