Reputation: 315
I want to change the timezone of my django project to Asia/Karachi. I have added this in my settings.py file:
TIME_ZONE = "Asia/Karachi"
Time zone of my postgres is also set to Asia/Karachi. But still when I create the objects, the time zone of DateTimeField is set to UTC.
class MyClass(models.Model):
name = models.CharField(max_length=64)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self) -> str:
return self.name
Now when I create the object of MyClass, created_at and updated_at are storing Time with UTC timezone. Why is this so and how can I fix it?
Edit:
In my drf interface, I can see the time zone in Asia/Karachi. But when I check time zone in shell, it gives time zone in UTC.
Upvotes: -1
Views: 529
Reputation: 3457
In settings.py file, you can set the TIME_ZONE
TIME_ZONE = 'Asia/Karachi'
You might need to set USE_TZ
as well.
USE_TZ = True
Upvotes: 0