This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow GMT timezones to be used in datetime.
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Decorater, martin.panter, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-03-23 06:35 by Decorater, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg290027 - (view) Author: Decorater (Decorater) * Date: 2017-03-23 06:35
I noticed that there is no ways to convert local times to GMT if I realize that some other object (sometimes from a server) is using GMT and they happen to be ahead of my current time. As such it would be great if one can convert their current time that can be in an datetime object to an GMT time to see how much time has passed since something happened on their zone if so desired (otherwise can cause undesired or undefined consequences).
msg290028 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-23 06:37
Use pytz (https://pypi.python.org/pypi/pytz).
msg290029 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-03-23 08:16
Does the “astimezone” method work for you? <https://docs.python.org/3.5/library/datetime.html#datetime.datetime.astimezone>

>>> from datetime import *
>>> aedt = timezone(+timedelta(hours=11))
>>> local = datetime.now(aedt)
>>> format(local)
'2017-03-23 19:14:41.410334+11:00'
>>> gmt = local.astimezone(timezone.utc)
>>> format(gmt)
'2017-03-23 08:14:41.410334+00:00'
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 74071
2017-11-25 00:09:17Decoratersetstatus: open -> closed
stage: resolved
2017-03-23 08:16:47martin.pantersetresolution: works for me

messages: + msg290029
nosy: + martin.panter
2017-03-23 06:37:17serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg290028
2017-03-23 06:35:08Decoratercreate