New submission from Adam Williamson <>:

Test script:

import pytz
import datetime
utc = pytz.timezone('UTC')
print(datetime.datetime(2017, 1, 1, tzinfo=utc).strftime('%s'))

Try running it with various system timezones:

[adamw@xps13k pagure (more-timezone-fun %)]$ TZ='UTC' python /tmp/
[adamw@xps13k pagure (more-timezone-fun %)]$ TZ='America/Winnipeg' python 
[adamw@xps13k pagure (more-timezone-fun %)]$ TZ='America/Vancouver' python 

That's Python 2.7.14; same results with Python 3.6.4.

This does not seem correct. The correct Unix time for an aware datetime object 
should be a constant: for 2017-01-01 00:00 UTC it *is* 1483228800 . No matter 
what the system's local timezone, that should be the output of strftime('%s'), 
surely. What it seems to be doing instead is just outputting the Unix time for 
2017-01-01 00:00 in the system timezone.

I *do* note that strftime('%s') is completely undocumented in Python; neither 
mentions it. However, it does exist, and is used in the real world; I found 
this usage of it, and the bug, in a real project, Pagure.

components: Library (Lib)
messages: 313169
nosy: adamwill
priority: normal
severity: normal
status: open
title: datetime.datetime.strftime('%s') always uses local timezone, even with 
aware datetimes
versions: Python 2.7, Python 3.6

Python tracker <>
Python-bugs-list mailing list

Reply via email to