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
frenzy
1,6604 gold badges17 silver badges24 bronze badges
-
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.Jeremy– Jeremy2019年06月13日 12:17:49 +00:00Commented Jun 13, 2019 at 12:17
-
timestamp with time zonefrenzy– frenzy2019年06月13日 15:37:40 +00:00Commented Jun 13, 2019 at 15:37
1 Answer 1
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:
answered Jun 25, 2020 at 9:21
frenzy
1,6604 gold badges17 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-sql