Created
January 5, 2021 14:14
-
-
Save carlosequiz/d50758dc8c3731a599ccc6734317b47b to your computer and use it in GitHub Desktop.
Dealing with Timezones and datetime
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
import datetime as dt | |
import pytz | |
date_time_str = '2021-01-06T01:10:54.269' | |
date_time_obj = dt.datetime.strptime(date_time_str, '%Y-%m-%dT%H:%M:%S.%f') | |
timezone = pytz.timezone('UTC') | |
timezone_date_time_obj = timezone.localize(date_time_obj) | |
timezone_date_time_now = dt.datetime.now(pytz.utc) | |
print(timezone_date_time_obj) | |
print(timezone_date_time_obj.tzinfo) | |
print(timezone_date_time_now) | |
print(timezone_date_time_now.tzinfo) | |
if timezone_date_time_obj < timezone_date_time_now: | |
print("It's before") | |
else: | |
print("It's after") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment