We want to get the current time in India in our Django project. In settings.py, UTC is there by default. How do we change it to IST?
You can get the current time in a particular timezone by using the datetime module with another module called pytz . You can then check for all available timezones with the snippet below: from datetime import datetime import pytz zones = pytz. all_timezones print(zones) # Output: all timezones of the world.
When USE_TZ is True, this is the default time zone that Django will use to display datetimes in templates and to interpret datetimes entered in forms.
Change the field TIME_ZONE
in the settings.py
. For the Indian standard time you will need:
TIME_ZONE = 'Asia/Kolkata'
For more information about the TIME_ZONE in Django you can see: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With