Waleed Farrukh
Waleed Farrukh

Reputation: 315

How to set Time zone to TIME_ZONE = "Asia/Karachi" in Django Project?

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. enter image description here

In python shell: enter image description here

Upvotes: -1

Views: 529

Answers (1)

Metalgear
Metalgear

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

Related Questions