언어/Python

[Python] Library - dateutil.parser

쟈누이 2022. 1. 13. 17:53
반응형

 

 

1. 라이브러리 정의


This module offers a generic date/time string parser which is able to parse most known formats to represent a date and/or time.

 

해당 모듈은 일반적인 날짜/시간 포멧으로 파싱이 가능한 날짜/시간 스트링 파서를 제공합니다.

 

 

 

 

2. 라이브러리 Functinos


parser.parse(parserinfo=None, **kwargs)[source]

Parse a string in one of the supported formats, using the parserinfo parameters.

Parameters:
  • timestr – A string containing a date/time stamp.
  • parserinfo – A parserinfo object containing parameters for the parser. If None, the default arguments to the parserinfo constructor are used.

 

Parameters:Returns:Raises:
  • default – The default datetime object, if this is a datetime object and not None, elements specified in timestr replace elements in the default object.
  • ignoretz – If set True, time zones in parsed strings are ignored and a naive datetime object 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 (tzname and tzoffset) and returning a time zone.
     
    This parameter is ignored if ignoretz is set.
  • The timezones to which the names are mapped can be an integer offset from UTC in seconds or a tzinfo object.
  • 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). If yearfirst is set to True, this distinguishes between YDM and YMD. If set to None, this value is retrieved from the current parserinfo object (which itself defaults to False).
  • 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 to None, the value is retrieved from the current parserinfo object (which itself defaults to False).
  • fuzzy – Whether to allow fuzzy parsing, allowing for string like “Today is January 1, 2047 at 8:21:00AM”.
  • fuzzy_with_tokens –If True, fuzzy is automatically set to True, and the parser will return a tuple where the first element is the parsed datetime.datetime datetimestamp and the second element is a tuple containing the portions of the string which were ignored:
  •  
Returns a datetime.datetime object or, if the fuzzy_with_tokens option is True, returns a tuple, the first element being a datetime.datetime object, the second a tuple containing the fuzzy tokens.
  • ParserError – Raised for invalid or unknown string formats, if the provided tzinfo is 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.

 

 

3. 참고 링크


https://dateutil.readthedocs.io/en/stable/parser.html

 

parser — dateutil 2.8.2 documentation

Parameters: default – The default datetime object, if this is a datetime object and not None, elements specified in timestr replace elements in the default object. ignoretz – If set True, time zones in parsed strings are ignored and a naive datetime ob

dateutil.readthedocs.io

 

반응형