Last active
October 8, 2021 20:07
-
-
Save RhetTbull/6a215a01e15383a5c0e6d69fcdc7dc23 to your computer and use it in GitHub Desktop.
Get offset from UTC as seconds for a python datetime.datetime timezone aware object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Get offset seconds from UTC from a datetime""" | |
import datetime | |
time1 = datetime.datetime(2021, 9, 1, 0, 0, 0, 0, tzinfo=datetime.timezone.utc) | |
offset_seconds = time1.tzinfo.utcoffset(time1).total_seconds() | |
print(time1, offset_seconds) | |
time2 = datetime.datetime( | |
2021, 9, 1, 0, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=-25200)) | |
) | |
offset_seconds = time2.tzinfo.utcoffset(time2).total_seconds() | |
print(time2, offset_seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment