関連するタイムゾーン ID (TZID=America/Los_Angeles) を持つ「20111014T090000」という形式の文字列があり、これを適切なオフセットを使用して秒単位の UTC 時間に変換したいと考えています。
問題は、出力時間が 1 時間ずれているようです (PDT である必要がある場合は PST にあります)。pytz を使用して timezo を支援しています。
import pytz
def convert_to_utc(date_time)
# date_time set to '2011-10-14 09:00:00' and is initially unaware of timezone information
timezone_id = 'America/Los_Angeles'
tz = pytz.timezone(timezone_id);
# attach the timezone
date_time = date_time.replace(tzinfo=tz);
print("replaced: %s" % date_time);
# this makes date_time to be: 2011-10-14 09:00:00-08:00
# even though the offset should be -7 at the present time
print("tzname: %s" % date_time.tzname());
# tzname reports PST when it should be PDT
print("timetz: %s" % date_time.timetz());
# timetz: 09:00:00-08:00 - expecting offset -7
date_time_ms = int(time.mktime(date_time.utctimetuple()));
# returns '1318611600' which is
# GMT: Fri, 14 Oct 2011 17:00:00 GMT
# Local: Fri Oct 14 2011 10:00:00 GMT-7
# when expecting: '1318608000' seconds, which is
# GMT: Fri, 14 Oct 2011 16:00:00 GMT
# Local: Fri Oct 14 2011 9:00:00 GMT-7 -- expected value
タイムゾーン ID に基づいて正しいオフセットを取得するにはどうすればよいですか?