I don't understand why the code below subtracts an hour of a UNIX epoch timestamp (in timezone UTC+1):
import datetime
import pytz
start_dt = datetime.datetime.fromtimestamp( 1362268800 , pytz.utc )
print start_dt
# prints datetime.datetime(2013, 3, 3, 0, 0, tzinfo=<UTC>)
print int( start_dt.strftime("%s") )
# prints: 1362265200 (which is 2013-03-02T23:00Z ) <--- I expected 1362268800
print start_dt.strftime("%Y-%m-%dT%H:%M:%SZ")
# prints: 2013-03-03T00:00:00Z
I've since hacked around my problem by using calendar.timegm( start_ts.timetuple() )
, but I fundamentally wonder what's wrong with the code above, and how to create datetime objects that are in UTC and where strftime would print the epoch timestamp.
Using "%s" is not specifically allowed according to the python docs. Should it be explicitly be not allowed (ie. raise an exception?) if it results in confusing results?
Using python 2.7.3