[New-bugs-announce] [issue23388] datetime.strftime('%s') does not take timezone into account
cameris
report at bugs.python.org
Tue Feb 3 12:24:02 CET 2015
New submission from cameris:
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).
----------
components: Library (Lib)
messages: 235338
nosy: cameris
priority: normal
severity: normal
status: open
title: datetime.strftime('%s') does not take timezone into account
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23388>
_______________________________________
More information about the New-bugs-announce
mailing list