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

前端 未结 1 1428
情歌与酒
情歌与酒 2021-01-06 15:26

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 f

1条回答
  •  广开言路
    2021-01-06 16:12

    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.

    0 讨论(0)
提交回复
热议问题