I have a datetime object saved in a django field. I query it, change the timezone and print it, this is the code and what I get:
Code:
print("event.date_start: %s" % event.date_start)
print("event.date_start.hour: %s" % event.date_start.hour)
print("event.date_start.tzinfo: %s" % event.date_start.tzinfo)
user_timezone = pytz.timezone("ETC/"+logged_user_profile.timezone)
print("user_timezone: %s" % user_timezone)
event_user_timezone = event.date_start.astimezone(user_timezone) # HERE
print("event_user_timezone: %s" % event_user_timezone)
print("event_user_timezone.hour: %s" % event_user_timezone.hour)
Prints:
event.date_start: 2020-11-17 18:00:00+00:00
event.date_start.hour: 18
event.date_start.tzinfo: UTC
user_timezone: Etc/GMT-5
event_user_timezone: 2020-11-17 23:00:00+05:00
event_user_timezone.hour: 23
As you can see, the initial tzinfo is UTC, then I use astimezone
to actualize it and change it to ETC/GMT-5
. But the time changes to GMT+5. Don't understand. If you need extra info plz let me know.