[issue36899] datetime utcfromtimestamp ignores astimezone

Piotr Kamoda report at bugs.python.org
Mon May 13 06:07:26 EDT 2019


Piotr Kamoda <kamoda.piotr at gmail.com> added the comment:

Ok, now I see that naive object assumes my timezone in some cases. That's still mind-boggling that utcfromtimestamp returns an object that shows utc hour but when astimezone is applied it reverts without converting the hour to local timezone.

See below as explanation:
>>> datetime.utcfromtimestamp(1557395250).astimezone(pytz.utc).strftime('%Y-%m-%d %H:%M:%S %z %Z')
'2019-05-09 07:47:30 +0000 UTC'
>>> datetime.utcfromtimestamp(1557395250).astimezone(get_localzone()).strftime('%Y-%m-%d %H:%M:%S %z %Z')
'2019-05-09 09:47:30 +0200 CEST'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36899>
_______________________________________


More information about the Python-bugs-list mailing list