Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
It is always a best practice to store dates in UTC. Do not ever store dates in your local timezone in which you will go to hell in your programming experience!

Given that you have saved your dates in UTC and would like to convert them into Asia/Tehran date in Python do like below:

date_format = '%Y-%m-%d %H:%M:%S'
local_tz = pytz.timezone('Asia/Tehran')
submit_time = dateutil.parser.parse(utc_date)
submit_time = submit_time.replace(tzinfo=pytz.utc).astimezone(local_tz)
output = submit_time.strftime(date_format)

#python #date #utc #strftime #dateutil #timezone #pytz