Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change my django server time

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..?

like image 881
Shiva Avatar asked Mar 22 '14 13:03

Shiva


People also ask

How do I change the timezone in 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.

What is the default timezone setting in Django?

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.

How does Django store current date and time?

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.

What is default Django server?

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.


2 Answers

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.

like image 200
Selcuk Avatar answered Oct 02 '22 15:10

Selcuk


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

like image 28
Akhil S Avatar answered Oct 02 '22 17:10

Akhil S