Jessie Liauw A Fong
Jessie Liauw A Fong

Reputation: 200

Django orm returning with timezone 0 while I want time zone with specifications

I moved from not using timezone to using timezone but I have a couple of questions about the handling of it. First of all my settings look like this:

TIME_ZONE = "Europe/Amsterdam"
USE_TZ = True

I now get the correct timezone back from the database but not in the right timezone. I suspect that when I have my TIME_ZONE on Europe/Amsterdam that I get that timezone back. But instead I get:

2020-09-27 23:00:07+00:00

But what I want to receive is:

2020-09-27 22:00:00+02:00

I can do this by using

timezone.localtime(date_object)

But is there a way to get the timezone back in the right format straight from the orm?

I am using Postgres 11 and Django 3.0.1

Upvotes: 0

Views: 332

Answers (1)

DJ Ramones
DJ Ramones

Reputation: 896

But is there a way to get the timezone back in the right format straight from the orm?

No, Django always gives the datetime objects in UTC; see this answer. Django refers to the TIME_ZONE when rendering templates or parsing forms, but before that, everything's in UTC unless explicitly transformed otherwise.

Upvotes: 1

Related Questions