classification
Title: datetime.strftime('%s') does not take timezone into account
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: add cross-platform support for %s strftime-format code
View: 12750
Assigned To: Nosy List: belopolsky, cameris, tunz
Priority: normal Keywords:

Created on 2015-02-03 11:24 by cameris, last changed 2018-03-25 16:02 by cheryl.sabella. This issue is now closed.

Messages (3)
msg235338 - (view) Author: cameris (cameris) Date: 2015-02-03 11:24
The following occured on linux with python 3.4.2, the machines local timezone is tz2:

>>> import datetime

>>> tz1 = datetime.timezone.utc; tz2 = datetime.timezone(datetime.timedelta(seconds=3600)); tz3 = datetime.timezone(datetime.timedelta(seconds=18000))

>>> d1 = datetime.datetime.now(tz=tz1); d2 = datetime.datetime.now(tz=tz2); d3 = datetime.datetime.now(tz=tz3)

>>> d1.timestamp(), d2.timestamp(), d3.timestamp()
(1422962091.603168, 1422962091.603181, 1422962091.603185)

>>> d1.strftime('%s'), d2.strftime('%s'), d3.strftime('%s')
('1422958491', '1422962091', '1422976491')

Or in other words:
>>> d1.strftime('%s') == str(int(d1.timestamp())), d2.strftime('%s') == str(int(d2.timestamp())), d3.strftime('%s') == str(int(d3.timestamp()))
(False, True, False)

Expected result of the last line would be (True, True, True).
msg235351 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2015-02-03 16:34
This looks like a duplicate of #12750.
msg235356 - (view) Author: cameris (cameris) Date: 2015-02-03 17:19
Yes, this seems to be exactly the same. Searching with "All text*: '%s'" didn't return anything, therefore I thought it is an unknown bug/behaviour. Well, sorry for the duplicate.
History
Date User Action Args
2018-03-25 16:02:01cheryl.sabellasetstatus: open -> closed
superseder: add cross-platform support for %s strftime-format code
resolution: duplicate
stage: resolved
2015-02-03 17:19:20camerissetmessages: + msg235356
2015-02-03 16:34:01belopolskysetmessages: + msg235351
2015-02-03 14:51:33r.david.murraysetnosy: + belopolsky
2015-02-03 14:30:36tunzsetnosy: + tunz
2015-02-03 11:24:02cameriscreate