I was trying to get the local time in the models section of my models.py file in Django. But this function returns the server time which is about 5 hours less than my local time, so, how do I get this correct?
date = models.DateTimeField(default=timezone.now)
Thanks In Advance!
On the settings.py, you set the timezone to your timezone.
eg
TIME_ZONE = 'Asia/Manila'
You can check the list of time zones here
Go in your settings.py and make changes
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Karachi' # Change it to your location
USE_I18N = True
USE_L10N = True
USE_TZ = True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.