I want to save the present date in database, but my Django server starting 13 hours earlier than the present time. Due to this the time is also changing when I use the following:
datetime.datetime.now()
I am using Python 2.7.5 with Django 1.5.4.
How can I display my present system date with django
..?
Time zone support is disabled by default. To enable it, set USE_TZ = True in your settings file. In Django 5.0, time zone support will be enabled by default. Time zone support uses zoneinfo , which is part of the Python standard library from Python 3.9.
We can say to Django that current timezone is IST. So, when we submit a form, date and time we pass will be considered in IST and then will be converted to default timezone(UTC) and will then be saved in the database.
from django. utils import timzone This enables you to have a timestamp on any model if you create a DateTimeField. For the date, you can use datetime. date.
Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.
If your server date and time is wrong, try to fix that first. If they are correct, you can add a timezone value into your settings.py
:
USE_TZ = True
TIME_ZONE = 'UTC'
Check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of valid time zones.
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = False
this is worked for me to set india timezone
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