Jun-15-2022, 02:46 PM
Pendulum make it easier,and it dos Timezones right.
No need to mess together 3-4 libraries to get stuff to work,eg datetime, pytz, tzdata, zoneinfo, dateutil...ect.
No need to mess together 3-4 libraries to get stuff to work,eg datetime, pytz, tzdata, zoneinfo, dateutil...ect.
>>> import pendulum >>> >>> d = '2022-06-14T13:00:00-07:00' >>> dt = pendulum.parse(d, strict=False) >>> dt DateTime(2022, 6, 14, 13, 0, 0, tzinfo=Timezone('-07:00')) >>> # Or >>> dt.fromisoformat(d) DateTime(2022, 6, 14, 13, 0, 0, tzinfo=UTC-07:00) >>> >>> dt.to_iso8601_string() '2022-06-14T13:00:00-07:00' >>> dt.to_datetime_string() '2022-06-14 13:00:00' >>> dt.to_formatted_date_string() 'Jun 14, 2022' >>> dt.to_rfc850_string() 'Tuesday, 14-Jun-22 13:00:00 -07:00'