Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Created October 22, 2019 16:44
Show Gist options
  • Save bugcy013/ce1976aee00465d274f4b07799ff9412 to your computer and use it in GitHub Desktop.
Save bugcy013/ce1976aee00465d274f4b07799ff9412 to your computer and use it in GitHub Desktop.
from datetime import datetime
import pytz
date_str = "2019-10-22T10:45:35Z"
utc_datetime_obj = pytz.utc.localize(datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ"))
ist_datetime_obj = utc_datetime_obj.astimezone(pytz.timezone("Asia/Kolkata"))\
# .strftime("%Y-%m-%d %H:%M:%S")
# print(type(datetime_obj))
# datetime_obj_utc = datetime_obj.replace(tzinfo=timezone('UTC'))
# print(datetime_obj_utc.strftime("%Y-%m-%d %H:%M:%S"))
print(utc_datetime_obj)
print(ist_datetime_obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment