0
class Book(models.Model):

    created_at=models.DateTimeField(auto_now_add=True)

this datetime is in utc timezone and I want to this datetime in to local timezone converted using query.

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
vivek
  • 11
  • 3

1 Answers1

0

You can make use of pytz for this.

First, find your timezone from pytz.all_timezones (ex: Asia/Kolkata)

import pytz
book_obj = Book.objects.get(pk=1)  # Replace query parameters according to your needs
my_timezone = pytz.timezone("Asia/Kolkata") # Replace Asia/Kolkata with your timezone
local_created_at = book_obj.created_at.astimezone(my_timezone)
anilkumarggk
  • 166
  • 1
  • 11