First of all, don't include time.strftime('%Z')
in your format. You're telling it your current GMT offset (including daylight saving being off) and it's [probably] using that to set tm_isdst.
Without that, you should get a struct 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 that to mktime, which will, given the -1
value, "guess" the DST value (I put "guess" in quotes because it will always be correct except for ambiguous 2AM 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 a correctly set DST flag:
>>> time.localtime(1338566400).tm_isdst
1
You can also skip the strptime step and directly pass the values to mktime:
>>> time.mktime((2012,6,1,12,0,0,-1,-1,-1))
1338566400.0