3

I have a data set which includes date/timestamps from New York WITHOUT timezone information. EDT or EST are not recorded.

Dates include daily data for several years, so it includes both:

  1. EDT Timezone
  2. EST Timezone

I want to translate those date/timestamps to Frankfurt time.

This involves using:

  1. CET Timezone
  2. CEST Timezone

Depending on the specific date.

I have seen that for the NY time, pytz includes timezone('US/Eastern'), which if I understood correctly includes both timezones (New York Timezones).

For Frankfurt, it seems that you need to explicitly specify CET or CEST (Frankfurt Timezones).

How shall this conversion be done using pytz?

benvc
  • 14,448
  • 4
  • 33
  • 54
M.E.
  • 4,955
  • 4
  • 49
  • 128
  • Possible duplicate of [pytz - Converting UTC and timezone to local time](https://stackoverflow.com/questions/25264811/pytz-converting-utc-and-timezone-to-local-time) – stovfl Jan 26 '19 at 06:45
  • While the post mentioned includes the information, the specific case of converting one city timezone to another one is very specific. It might be not intuitive to look for "UTC" and "local time" to fix this issue (at least not for every one). – M.E. Jan 26 '19 at 11:08

1 Answers1

7

You can convert from New York time to Frankfurt time by using localize() to create your naive datetime objects in New York time and astimezone() to then convert them to Frankfurt (Berlin) time. Using the timezone name (rather than a specific timezone abbreviation that only applies during part of the year) will handle the daylight savings difference for you.

For example:

from datetime import datetime
from pytz import timezone

newyork_tz = timezone('America/New_York')
berlin_tz = timezone('Europe/Berlin')

newyork = newyork_tz.localize(datetime(2018, 5, 1, 8, 0, 0))
berlin = newyork.astimezone(berlin_tz)
print(newyork)
print(berlin)
# OUTPUT
# 2018-05-01 08:00:00-04:00
# 2018-05-01 14:00:00+02:00
benvc
  • 14,448
  • 4
  • 33
  • 54