Time zone database

Working with Dates and Times in Python

Max Shron

Data Scientist and Author

Working with Dates and Times in Python

Time zone database

# Imports
from datetime import datetime
from dateutil import tz

tz database

Working with Dates and Times in Python

Time zone database

# Imports
from datetime import datetime
from dateutil import tz

# Eastern time
et = tz.gettz('America/New_York')

tz database

  • Format: 'Continent/City'
Working with Dates and Times in Python

Time zone database

# Imports
from datetime import datetime
from dateutil import tz

# Eastern time
et = tz.gettz('America/New_York')

tz database

  • Format: 'Continent/City'
  • Examples:
    • 'America/New_York'
    • 'America/Mexico_City'
    • 'Europe/London'
    • 'Africa/Accra'
Working with Dates and Times in Python

Time zone database

# Last ride
last = datetime(2017, 12, 30, 15, 9, 3, tzinfo=et)
print(last)
2017-12-30 15:09:03-05:00
Working with Dates and Times in Python

Time zone database

# Last ride
last = datetime(2017, 12, 30, 15, 9, 3, tzinfo=et)
print(last)
2017-12-30 15:09:03-05:00
# First ride
first = datetime(2017, 10, 1, 15, 23, 25, tzinfo=et)
print(first)
2017-10-01 15:23:25-04:00
Working with Dates and Times in Python

Time zone database

Working with Dates and Times in Python

Preparing Video For Download...