There are at least two issues:
- you shouldn’t pass a timezone with non-fixed UTC offset such as
"US/Pacific"as tzinfo parameter directly. You should usepytz.timezone("US/Pacific").localize()method instead .strftime('%s')is not portable, it ignores tzinfo, and it always uses the local timezone. Usedatetime.timestamp()or its analogs on older Python versions instead.
To make a timezone-aware datetime in the given timezone:
#!/usr/bin/env python
from datetime import datetime
import pytz # $ pip install pytz
tz = pytz.timezone("US/Pacific")
aware = tz.localize(datetime(2011, 2, 11, 20), is_dst=None)
To get POSIX timestamp:
timestamp = (aware - datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()
(On Python 2.6, see totimestamp() function on how to emulate .total_seconds() method).