I am looking for a function from the django.utils.library that would take a datetime from a specified timezone and return its UTC equivalent. Does such a function exist?
Asked
Active
Viewed 42 times
0
-
do you need this functionality done using django's utils library or would you like a solution based on datetime library ? – Sahil Jun 05 '20 at 21:01
-
I am also interested in the datetime library solution – Extranomical Jun 05 '20 at 21:02
-
also just to confirm, do you want to localize the time ? – Sahil Jun 05 '20 at 21:03
1 Answers
1
To convert a datetime object that already has timezone information to another timezone (UTC in this case) you can use django.utils.timezone.localtime
from django.utils.timezone import localtime, utc
datetime_object_as_utc = localtime(datetime_object, timezone=utc)

Iain Shelvington
- 31,030
- 3
- 31
- 50