79774175

Date: 2025-09-24 20:57:16
Score: 0.5
Natty:
Report link

When you use datetime.fromisoformat(test_date[:-1]), it's parsing the string into a naive datetime object. Even though the string effectively represents UTC (due to the 'Z'), fromisoformat without a timezone specified will create a naive datetime.

from datetime import datetime, timezone
from zoneinfo import ZoneInfo
from tzlocal import get_localzone

test_date = "2025-10-01T19:20:00.000Z"

utc_datetime = datetime.fromisoformat(test_date[:-1]).replace(tzinfo=timezone.utc)

local_zone = get_localzone()
d = utc_datetime.astimezone(local_zone)

print(d)
print(d.strftime('%a %b %d %-I:%M %p').upper())

Output:

2025-10-01 14:20:00-05:00
WED OCT 01 2:20 PM
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you use
  • Low reputation (1):
Posted by: Teapot code