TGViewer
Learn Python Coding Learn Python Coding @pythonre · 40.8K subscribers
Post #8920 2.88K
Advice on clean code in Python

Don't use "naive" datetime without time zones. Store and process time in UTC, and display it to the user in his local time zone

import datetime
from zoneinfo import ZoneInfo

# BAD
now = datetime.datetime.now()

print(now.isoformat())
# 2025-10-21T15:03:07.332217

# GOOD
now = datetime.datetime.now(tz=ZoneInfo("UTC"))
print(now.isoformat())
# 2025-10-21T12:04:22.573590+00:00

print(now.astimezone().isoformat())
# 2025-10-21T15:04:22.573590+03:00
  • ❤ 2
More from @pythonre
  1. Oct 13, 2026https://substack.com/@husseinsheikho?utm_source=share&utm_medium=android&r=3hwnr8 Follow m…
  2. Oct 10, 2026📚 Download 10 Python books for FREE: 1. Think Python — O’Reilly https://t.co/X7y3pX68IW 2…
  3. Oct 7, 2026Python Lists: A Quick Reference 🐍 * Definition: Lists are ordered, mutable collections th…
  4. Oct 7, 2026📱 270 tools for Python developers The repository contains: 🫡 Linters and formatters; 🫡…
  5. Oct 7, 2026Hands On Python Data Science - Data Science Bootcamp Master Python for Data Science with R…
  6. Oct 6, 2026Post #9851
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →