Python Zipfile lib在修改时间内具有秒的奇怪行为

Python Zipfile lib在修改时间内具有秒的奇怪行为,python,zipfile,Python,Zipfile,使用zipfile模块时,我发现它的工作原理有些奇怪 我正在压缩一个文件,最后修改的attr时间是:13:40:31(HH:MM:SS) 当我压缩和解压文件时,它的最后修改时间是13:40:30(丢失1秒) 围绕这一点做了一些测试,我使用ZipInfo对象手动将上次修改的时间设置为13:40:31,但仍然得到13:40:30 我也试着设定到13:40:41,然后我得到了13:40:40 尝试将任何其他值设置为秒,效果很好,因此如果我将其设置为13:40:32,解压文件时就可以了 有什么线索吗?我

使用zipfile模块时,我发现它的工作原理有些奇怪

我正在压缩一个文件,最后修改的attr时间是:13:40:31(HH:MM:SS) 当我压缩和解压文件时,它的最后修改时间是13:40:30(丢失1秒)

围绕这一点做了一些测试,我使用ZipInfo对象手动将上次修改的时间设置为13:40:31,但仍然得到13:40:30

我也试着设定到13:40:41,然后我得到了13:40:40

尝试将任何其他值设置为秒,效果很好,因此如果我将其设置为13:40:32,解压文件时就可以了

有什么线索吗?我错过什么了吗

操作系统:Windows 10(64位) Python:3.7

试验 只需压缩任何文件,然后解压缩它,并比较上次修改的时间

file = 'testfile.txt'

zf = zipfile.ZipFile(file='test.zip', mode='w', compression=zipfile.ZIP_DEFLATED)

info = zipfile.ZipInfo(file, 
    date_time=(2020, 9, 23, 13, 40, 31))

zf.writestr(info, open(file, 'r').read(), zipfile.ZIP_DEFLATED, 6)
zf.close()

提前谢谢

默认情况下,zip文件将时间戳存储为2秒的精度。这可以追溯到DOS统治世界的时候,每一点都很重要。下面是ZIp规范()中对其工作方式的定义

尽管现代zip文件中仍然存在默认的遗留文件,但大多数zip实现也使用扩展属性来准确存储时间戳


看起来Python不支持该功能。

感谢您的回复,我不知道这2秒的准确性。我应该寻找其他lib-to-zip文件,然后才找到更多的信息,它被报告为bug,但似乎被忽略了,因为zipfile遵循zip标准:该票据只讨论具有2秒精度的遗留日期/时间字段。在zip文件中支持更精确时间的扩展也是zip标准的一部分。大多数现代命令行实现都支持zip文件的读写扩展。
   4.4.6 date and time fields: (2 bytes each)
 
       The date and time are encoded in standard MS-DOS format.
       If input came from standard input, the date and time are
       those at which compression was started for this data. 
       If encrypting the central directory and general purpose bit 
       flag 13 is set indicating masking, the value stored in the 
       Local Header will be zero. MS-DOS time format is different
       from more commonly used computer time formats such as 
       UTC. For example, MS-DOS uses year values relative to 1980
       and 2 second precision.