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
#python #date #utc #strftime #dateutil #timezone #pytz
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
It is best practice to always set server date/time to UTC. In debian in order to configure your time and set it to UTC, do as follow:
Now select
To check your server date/time issue date command:
#date #dpkg-reconfigure #tzdata #UTC #timezone
sudo dpkg-reconfigure tzdata
Now select
None of the above
or Etc
and then press OK. Now select UTC
. You're done.To check your server date/time issue date command:
root@serv01:~# date
Mon Mar 5 11:20:59 UTC 2018
#date #dpkg-reconfigure #tzdata #UTC #timezone