Anatol Zakrividoroga
Anatol Zakrividoroga

Reputation: 4518

How to Convert a Date to Django Timezone Aware Datetime

I am trying to convert a DateTime with the UTC time zone to Django datetime that respects the time zone of my date.

Here is my settings.py:

TIME_ZONE = 'US/Pacific'

USE_TZ = True

Here is the date I am trying to convert to the right time zone for django: datetime.datetime(2020, 2, 20, 8, 55, 48, 846000)

I used the make_aware function provided by Django but I can see the date isn't converted to the time zone in my settings.py when I save the Django Modal with a DateTime field

from django.utils.timezone import make_aware

Upvotes: 2

Views: 1506

Answers (1)

Zaraki Kenpachi
Zaraki Kenpachi

Reputation: 5730

Django doc

When time zone support is enabled (USE_TZ=True), Django uses time-zone-aware datetime objects. If your code creates datetime objects, they should be aware too. In this mode, the example above becomes:

Upvotes: 1

Related Questions