"zoning" a naive datetime object / daylight savings

Adam Monsen haircut at gmail.com
Wed Aug 31 23:53:02 EDT 2005


Ok, I think I figured this out. Comments/criticisms welcome.

----------------------------------8<----------------------------------
import datetime, os, time
from pytz import UTC
old_tz = os.environ.get('TZ')
os.environ['TZ'] = 'Europe/Amsterdam'
time.tzset()
dutchDateParts = (2005, 8, 10, 17, 26, 0, 2, 222, -1)
timestamp = time.mktime(dutchDateParts)
if old_tz: os.environ['TZ'] = old_tz
else: del os.environ['TZ']
time.tzset()
print datetime.datetime.fromtimestamp(timestamp, UTC)
---------------------------------->8----------------------------------


The 9-integer time tuple could be fetched using the code posted here:
http://snipurl.com/hcvs
same URL, not snipped:
http://groups.google.com/group/comp.lang.python/msg/65d8f116dfd59dd1

--
Adam Monsen
http://adammonsen.com/




More information about the Python-list mailing list