Created
December 20, 2021 19:20
-
-
Save bashkirtsevich/0c78797946158be97027f1c59df46ab1 to your computer and use it in GitHub Desktop.
UTC Timezone Diff
This file contains hidden or 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
from datetime import datetime | |
from pytz import UTC | |
from pytz import timezone | |
def utc_tz_diff(tz): | |
diff = (t1 := UTC.localize(now := datetime.utcnow())) - (t2 := timezone(tz).localize(now).astimezone(UTC)) | |
return f"{'+' if t1 > t2 else '-'}{diff.seconds // 3600:02}:{diff.seconds // 60 % 60:02}" if diff.seconds else "Z" | |
DATETIME_FORMAT = f"%Y-%m-%dT%H:%M:%S{utc_tz_diff(TIME_ZONE)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment