First of all, do not include time.strftime('%Z') in your format. You say that your current clockwise offset (including daylight saving time is turned off), and that is [possible], using this to set tm_isdst.
Without this, you should get a structure with tm_isdst=-1 :
>>> time1 = time.strptime("2012-06-01 12:00:00", "%Y-%m-%d %H:%M:%S") >>> time1 time.struct_time(tm_year=2012, tm_mon=6, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=153, tm_isdst=-1)
Now you can pass this to mktime, which, given the value -1 , will “guess” the DST value (I put “guess” in quotation marks because it will always be correct, except for the 2AM ambiguous cases). This will give the absolute time in time() format.
>>> time.mktime([previous value]) # my timezone is US Eastern 1338566400.0
Then you can call localtime with this value, and it will have the DST flag set correctly:
>>> time.localtime(1338566400).tm_isdst 1
You can also skip the strptime step and pass the values directly to mktime:
>>> time.mktime((2012,6,1,12,0,0,-1,-1,-1)) 1338566400.0
Random832 Nov 19 '12 at 13:26 2012-11-19 13:26
source share