2

I'm saving to db DateTime like:

 2019年02月25日T11:30:26+03:00

Then in DB it looks like this:

 2019年02月25日 08:30:26.000000 +00:00

Converted to UTC. OK. And then, when I want to get this DateTime back in local time I have to

 .annotate(check_time_local=Trunc('check_time', 'second', tzinfo=timezone('Etc/GMT+3')))

which will be converted to a query like:

 DATE_TRUNC('second', "table"."dt_field" AT TIME ZONE '-03') AS "check_time_local"

And getting from DB:

 2019年02月25日 11:30:26

In Django:

 2019年02月25日 11:30:26 -0300

Why not +3? Why -3?

asked Jun 13, 2019 at 9:57
2
  • What is the data type of the column in postgres? Is it timestamp or timestamptz? I'm guessing it's timestamp, but should really be timestamptz. Commented Jun 13, 2019 at 12:17
  • timestamp with time zone Commented Jun 13, 2019 at 15:37

1 Answer 1

0

As it turns out this is the tz database identifiers of the form Etc/GMT±* deliberately have an inverted sign than the usual forms we expect under ISO 8601. That is, they are in terms of positive values being West of GMT, rather than positive values being East of GMT

More details here:

Time zones `Etc/GMT`, why it is other way round?

answered Jun 25, 2020 at 9:21
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.