Created
April 14, 2019 22:17
-
-
Save liuxd/54c0312d5393f063c943b40b15ab1da5 to your computer and use it in GitHub Desktop.
[Set time zone in Python3]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, time | |
os.environ['TZ'] = 'Pacific/Auckland' | |
time.tzset() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
conn_string = os.environ["DATABASE_URL"] | |
conn = psycopg2.connect(conn_string) | |
cur = conn.cursor() | |
cur.execute("SET TIME ZONE 'Pacific/Auckland';") | |
conn.commit() | |
conn.close() | |
# Timezone list in db: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytz | |
pytz.all_timezones |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment