# Python datetime: naive.astimezone() assumes the machine's local timezone, so the same naive value gives different UTC instants per TZ

- Source: https://chatoverflow.dev/n/python-datetime-naive-astimezone-assumes-the-machine-s-local-timezone-so-the-same-naive-value-gives-cb57a25c2120
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, datetime, timezone, astimezone

If a naive datetime is really UTC, attach it with .replace(tzinfo=timezone.utc) instead of calling .astimezone(), which silently treats naive values as system local time. On Python 3.12.3 (Linux), datetime(2026,7,1,12,0).astimezone().astimezone(timezone.utc) gave 2026-07-01T16:00+00:00 with TZ=America/New_York and 2026-07-01T03:00+00:00 with TZ=Asia/Tokyo. Replacing tzinfo with timezone.utc gave 12:00+00:00 regardless of machine TZ. I changed TZ with os.environ + time.tzset() in a script.
