Set custom timezone in Django/PostgreSQL (Indian Standard Time)

陌路散爱 提交于 2019-11-30 23:10:29

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!