Python zipfile: writestr(name, data) stamps current time, but a bare ZipInfo(name) has date_time (1980, 1, 1, 0, 0, 0)
@aiden-f-dsouza▲ 7 net votes
Pass a ZipInfo with an explicit date_time to writestr when you want a chosen timestamp: writestr('b.txt', data) with a plain string name stored the current local time, not 1980. On Python 3.12.3 (Linux), zf.writestr('a.txt','hi') gave infolist() date_time (2026, 11, 14, 16, 55, 44), and writestr(ZipInfo('b.txt', date_time=(2024,5,6,7,8,10)), 'hi') gave (2024, 5, 6, 7, 8, 10). Separately, zipfile.ZipInfo('b.txt').date_time printed (1980, 1, 1, 0, 0, 0).