在Django / PostgreSQL(印度标准时间)中设置自定义时区 [英] Set custom timezone in Django/PostgreSQL (Indian Standard Time)
问题描述
在Django 设置时区的文档中,<时间段的href =http://www.postgresql.org/docs/current/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE =nofollow>可用选项列表实际上是postgres的时区参数字符串。所以看起来Django使用Postgres来检索时间。
如果是这样,那么问题是IST用来表示印度语& 以色列标准时间,但postgres使用 $ / search?q = ISTrel =nofollow> IST 。 b
$ b
不仅如此,Postgres也错过了其他一些国家,如尼泊尔(GMT + 5:30)和一些太平洋岛屿的时区。
所以,有什么办法可以在Postgres或Django中设置自定义时区字符串(如印度的GMT + 5:30,尼泊尔的GMT + 5:45)?
对于印度:
SELECT now()AT TIME ZONE 亚洲/加尔各答;
SELECT now():: timestamp AT TIME ZONE'Asia / Kolkata';
SELECT now():: timestamp AT TIME ZONE'5:30';
对于尼泊尔:
SELECT now():: timestamp AT TIME ZONE'Asia / Katmandu';
SELECT now():: timestamp AT TIME ZONE'NPT';
设置整个会话的时区:
SET时区'亚洲/加尔各答';
要重置它(到postgresql.conf中设置的时区:
RESET时区;
在系统视图中查找更多 pg_timezone_names
和 pg_timezone_abbrevs
SELECT *
FROM pg_timezone_names
WHERE utc_offset BETWEEN '05:00:00'和'06:00:00'
ORDER BY utc_offset;
SELECT *
FROM pg_timezone_abbrevs
WHERE utc_offset BETWEEN '05:00:00'AND '06:00:00'
ORDER BY utc_offset;
PostgreSQL手册关于 AT TIME ZONE
构造。关于时区。
In Django documentation for setting timezone, the list of available choices for timezone are actually postgres timezone parameter strings. So it seems Django uses Postgres for retrieving time.
If so, then the problem is that IST is used to denote both Indian & Israel Standard Time, but postgres uses IST for Israel Standard Time (potentially confusing over a 6th of world's population) and there is NO timezone string for Indian Standard Time.
Not just that, Postgres also misses timezone for some other countries like Nepal (GMT+5:30) and some Pacific Islands.
So, is there any way by which I can set custom timezone string (like GMT+5:30 for India, GMT+5:45 for Nepal, etc.) in Postgres or Django?
For India:
SELECT now() AT TIME ZONE 'Asia/Calcutta';
SELECT now()::timestamp AT TIME ZONE 'Asia/Kolkata';
SELECT now()::timestamp AT TIME ZONE '5:30';
For Nepal:
SELECT now()::timestamp AT TIME ZONE 'Asia/Katmandu';
SELECT now()::timestamp AT TIME ZONE 'NPT';
To set the time zone for the whole session:
SET time zone 'Asia/Calcutta';
To reset it (to the time zone set in postgresql.conf:
RESET time zone;
Find more in the system views pg_timezone_names
and pg_timezone_abbrevs
SELECT *
FROM pg_timezone_names
WHERE utc_offset BETWEEN '05:00:00' AND '06:00:00'
ORDER BY utc_offset;
SELECT *
FROM pg_timezone_abbrevs
WHERE utc_offset BETWEEN '05:00:00' AND '06:00:00'
ORDER BY utc_offset;
PostgreSQL manual about AT TIME ZONE
construct. About time zones.
这篇关于在Django / PostgreSQL(印度标准时间)中设置自定义时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!