Custom timezone setting in Django / PostgreSQL (Indian Standard Time)

In the Django documentation for setting the time zone, the list of available options for the time zone are actually strings of the postgres time range parameters. So Django uses Postgres to get the time.

If so, the problem is that IST is used to indicate Indian and Israel Standard Time, but postgres uses IST for Standard Time in Israel (perhaps confusing more than 6 people in the world), and there is no timeline for Indian Standard Time.

Not only that, Postgres also misses the time zone for some other countries, such as Nepal (GMT + 5: 30) and some Pacific islands.

So, is there a way by which I can set a custom timezone line (e.g. GMT + 5: 30 for India, GMT + 5: 45 for Nepal, etc.) in Postgres or Django?

+3
source share
1 answer

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 an entire session:

 SET time zone 'Asia/Calcutta'; 

In reset, it (in the time zone set in postgresql.conf:

 RESET time zone; 

Find pg_timezone_names and pg_timezone_abbrevs in the system views

 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 Guide on AT TIME ZONE . About time zones .

+4
source

Source: https://habr.com/ru/post/1260323/


All Articles