Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django DateTimeField says 'You are 5.5 hours ahead of server time.'

In one of my model I am storing time_stamp = models.DateTimeField(default=timezone.now)

But when I save the model it says You are 5.5 hours ahead of server time. for example local time in my machine is 13:02 but after saving what gets stored in db is 7:16

I got one related here but it does not an have a satisfying answer...

models.py

class Comment(models.Model):
    time_stamp = models.DateTimeField(default=timezone.now)

    def save(self, *args, **kwargs):
        ''' On save, update timestamps '''
        if not self.id:
            self.time_stamp = timezone.now()
        return super(Comment, self).save(*args, **kwargs)
like image 971
Jayesh Singh Avatar asked Dec 29 '18 07:12

Jayesh Singh


2 Answers

As you are 5.5 hrs ahead of server time, I am assuming, you are in India.
So put appriopriate timezone in settings.py

TIME_ZONE = 'Asia/Kolkata'

If somewhere else, set accordingly

like image 121
coderDude Avatar answered Oct 22 '22 09:10

coderDude


Make sure you make the following change in the settings.py file in your Django project.

Change in settings.py file

like image 32
Sumit Banik Avatar answered Oct 22 '22 10:10

Sumit Banik