Skip to content

Instantly share code, notes, and snippets.

@liuxd
Created April 14, 2019 22:17
Show Gist options
  • Save liuxd/54c0312d5393f063c943b40b15ab1da5 to your computer and use it in GitHub Desktop.
Save liuxd/54c0312d5393f063c943b40b15ab1da5 to your computer and use it in GitHub Desktop.
[Set time zone in Python3]
import os, time
os.environ['TZ'] = 'Pacific/Auckland'
time.tzset()
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
import pytz
pytz.all_timezones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment