标签:des style blog http io ar color os sp
本文参考http://stackoverflow.com/questions/9813243/extract-files-from-zip-file-and-retain-mod-date-python-2-7-1-on-windows-7
1 import os 2 import time 3 from zipfile import ZipFile 4 5 zf = ZipFile(‘archive.zip‘, ‘r‘) 6 for zi in zf.infolist(): 7 zf.extract(zi) 8 date_time = time.mktime(zi.date_time + (0, 0, -1)) 9 os.utime(zi.filename, (date_time, date_time)) 10 zf.close()
time.mktime()函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象或一个完整的9位元组作为参数,返回用秒数来表示时间的浮点数。
Index | Attribute | Values |
---|---|---|
0 | tm_year | (for example, 1993) |
1 | tm_mon | range [1, 12] |
2 | tm_mday | range [1, 31] |
3 | tm_hour | range [0, 23] |
4 | tm_min | range [0, 59] |
5 | tm_sec | range [0, 61]; see (2) in strftime() description |
6 | tm_wday | range [0, 6], Monday is 0 |
7 | tm_yday | range [1, 366] |
8 | tm_isdst | 0, 1 or -1; see below |
上述代码第8行就是构造该元组,(0, 0, -1)分别表示tm_wday,tm_yday,tm_isdst(-1表示夏令时未知)
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/cygnushan/p/4146293.html