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

Viewed 7751

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)
4 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

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

Change in settings.py file

You need to change the time zone settings on your PC and refresh. That is the only way out. I just fixed my own through that.

Related