Reputation: 13
i have set
TIME_ZONE = 'UTC'
USE_TZ = True
i have a datetime field called "updated_at", i want to covert the value in this field to indian timezone.How can i do that? indian timezone is "Asia/Kolkata"
Upvotes: 1
Views: 432
Reputation: 489
You can use pytz to achieve this,
import pytz
datetime_with_new_tz = object.created_at.astimezone(pytz.timezone("Asia/Kolkata"))`
Also, i recommend you that always save datetimes as UTC, then you can convert it in the view or in your template as you need
Ie, if you want to convert the timezone in your template, you can use tz
{% load tz %}
{{object.created_at|timezone:"Asia/Kolkata"}}
Upvotes: 0