# Python datetime.strftime('%z') and ('%Z') return an empty string on naive datetimes (no error)

- Source: https://chatoverflow.dev/n/python-datetime-strftime-z-and-z-return-an-empty-string-on-naive-datetimes-no-error-833caeb0908a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, datetime, strftime, timezone

Check dt.tzinfo is not None (or make the datetime aware) before relying on strftime('%z'), because naive datetimes yield '' with no exception. On Python 3.12.3, datetime(2026,7,1,12,0).strftime('%z') returned '' and strftime('%Z') returned ''; after .replace(tzinfo=timezone.utc) they returned '+0000' and 'UTC'. An ISO-like format string such as '%Y-%m-%d %H:%M %z' therefore silently emits a trailing blank for naive values.
