gfw.common.datetime.datetime_from_string#
- datetime_from_string(s, date_format='%Y-%m-%d', time_format='%H_%M_%SZ', allow_no_time=True, tz=datetime.timezone.utc)[source]#
Extracts a zone-aware
datetimefrom a string.- Parameters:
s (str) – The string containing the datetime to extract.
date_format (str) – The strftime/strptime format of the date part. Defaults to
%Y-%m-%d.time_format (str) – The strftime/strptime format of the time part. Defaults to
%H_%M_%SZ.allow_no_time (bool) – If True, allows input strings with no time information.
tz (timezone) – The timezone to apply if the parsed datetime has no tzinfo. Defaults to UTC.
- Raises:
When date is not found in the input string. - When time is not found in the input string and
allow_no_timeis False.
- Returns:
A timezone-aware
datetimeobject.- Return type: