You need to use just the dateutil.tz.tzoffset()
type; pytz.timezone
only takes names, not dateutil.tz
objects.
The .localize()
method is only needed for pytz
-supplied timezones as they contain historic offsets as well, and they need to be applied to a datetime
object using a little more care than just .replace()
can do.
If the timestamp is a UNIX epoch value in UTC, then use fromtimestap
with the timezone as a second argument:
>>> print datetime.fromtimestamp(utc_time/1000, tzinfooff)
2014-03-10 08:00:00-04:00
Or you could translate from UTC, using datetime.astimezone()
:
>>> from dateutil.tz impor tzutc
>>> dt_utc = datetime.utcfromtimestamp(utc_time/1000).replace(tzinfo=tzutc())
>>> print dt_utc.astimezone(tzinfooff)
2014-03-10 08:00:00-04:00