79129528

Date: 2024-10-26 21:58:51
Score: 1
Natty:
Report link

As mentioned by @MT0 using zoneinfo works correctly:

>>> dt(2024, 1, 1, 7, 40, 0, tzinfo=pytz.timezone('America/New_York')).isoformat()
'2024-01-01T07:40:00-04:56'
>>> dt(2024, 1, 1, 7, 40, 0, tzinfo=zoneinfo.ZoneInfo('America/New_York')).isoformat()
'2024-01-01T07:40:00-05:00'
>>> dt(2024, 10, 10, 7, 40, 0, tzinfo=zoneinfo.ZoneInfo('America/New_York')).isoformat()
'2024-10-10T07:40:00-04:00'

In January, NY observes winter time, which is UTC-5, and therefore the offset is correct. If you want to see the -04:00 offset, change date to one where DST is observed, like Oct 10.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @MT0
  • Low reputation (1):
Posted by: Gendalph