[
  {
    "Id": "526565",
    "ThreadId": "235907",
    "Html": "\r\n<p>When I create and unzip a zip file with DotNetZip, the time is off by the difference between time zones I created it in and the one I extract it in.&nbsp; For instance, let's say I zip up the file &quot;AnExample.XLS&quot; at 5am on the Pacific Coast (PST), then copy\r\n the zip file to a machine on the East Coast and unzip it with DotNetZip using the code below.&nbsp; The &quot;file modified&quot; timestamp in the resulting unzipped file shows 8am.</p>\r\n<p>I need the timestamps on the zipped files (for reasons of my own) to be the extracted to the same times as they were in their own time zone. The aforementioned &quot;AnExample.XLS&quot; file would need a 5am timestamp in any timezone where I extract it.&nbsp; When\r\n I unzip it with (for instance) WinRAR, it works out fine; but I'd much rather be using DotNetZip.</p>\r\n<p>It seems like the extraction pulls the UTC values in &quot;ZipEntry.ModifiedTime&quot; and the system applies the UTC Offset of the local time.&nbsp; If I query the contents of the zip file with DotNetZip, I get the correct local times from ZipEntry.LastModified.\r\n I was planning to load the values and filenames into a dictionary and rewrite the timestamps on each after extraction. There shouldn't be any duplicate filenames, so it would work, but is there a more elegant solution?</p>\r\n<p>&nbsp;&nbsp;&nbsp; Using zip As ZipFile = ZipFile.Read(strZipToOpen)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; If strPassword &lt;&gt; &quot;&quot; Then zip.Password = strPassword<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; If Not zip.Comment Is Nothing Then strComment = zip.Comment<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; totalEntriesToProcess = zip.Entries.Count<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetProgressBarMax(zip.Entries.Count)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddHandler zip.ExtractProgress, New EventHandler(Of ExtractProgressEventArgs)(AddressOf zip_ExtractProgress)<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.ExtractAll(strExtractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)<br>\r\n&nbsp;&nbsp;&nbsp; End Using</p>\r\n",
    "PostedDate": "2010-11-24T10:46:05.15-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "526600",
    "ThreadId": "235907",
    "Html": "\r\n<blockquote style=\"border:solid .1em #ccc; font-style:italic; margin:.25em 1em 0 1em; padding:0 .25em 0 .25em\">\r\n<strong>ChrisFontenot13 wrote:</strong><br>\r\n<p>When I create and unzip a zip file with DotNetZip, the time is off by the difference between time zones I created it in and the one I extract it in.&nbsp; For instance, let's say I zip up the file &quot;AnExample.XLS&quot; at 5am on the Pacific Coast (PST), then copy\r\n the zip file to a machine on the East Coast and unzip it with DotNetZip using the code below.&nbsp; The &quot;file modified&quot; timestamp in the resulting unzipped file shows 8am.</p>\r\n<p>I need the timestamps on the zipped files (for reasons of my own) to be the extracted to the same times as they were in their own time zone. The aforementioned &quot;AnExample.XLS&quot; file would need a 5am timestamp in any timezone where I extract it.&nbsp; When\r\n I unzip it with (for instance) WinRAR, it works out fine; but I'd much rather be using DotNetZip.</p>\r\n<p>It seems like the extraction pulls the UTC values in &quot;ZipEntry.ModifiedTime&quot; and the system applies the UTC Offset of the local time.&nbsp; If I query the contents of the zip file with DotNetZip, I get the correct local times from ZipEntry.LastModified.\r\n I was planning to load the values and filenames into a dictionary and rewrite the timestamps on each after extraction. There shouldn't be any duplicate filenames, so it would work, but is there a more elegant solution?&nbsp;</p>\r\n</blockquote>\r\n<p>Yes, by default DotNetZip uses UTC timestamps for entries you add to ZipFiles. When you extract a zipfile using DotNetZip, and the zipfile was created with DotNetZip, then upon extraction the&nbsp;extracted files will get the UTC time (8am in NYC is the\r\n same as 5am in Los Angeles).&nbsp; When you display the timestamp for the file in Windows Explorer or some other tool, it will typically apply the UTC offset and display the local time. &nbsp; If for some reason you don't want the actual UTC time to be applied\r\n to entries in a zip file, you can do one of these things:</p>\r\n<ol>\r\n<li>you can modify the ModifiedTime property on each entry, using an offset for each timezone.&nbsp;&nbsp; This would require you to know the zipping timezone, the unzipping timezone, and be able to calculate the offset between the two.&nbsp; There are two\r\n options here:\r\n<ol>\r\n<li>you apply the delta at the time of creation of the zip.&nbsp; In this case, there is no one-size fits all solution. &nbsp;If some of your zips need to be unzipped in London, and some in New York, and then you'd have to apply a different delta, depending\r\n on the eventual unzip location.&nbsp; In other words, you'd need to produce one zipfile for eventual unzip in NY, and a second one for eventual unzip in London.&nbsp;\r\n</li><li>Apply the delta at the time of unzip.&nbsp; In this case you'd assume the zip creation location is fixed.&nbsp;&nbsp; Your approach of iterating through the entries and adjusting the time would work.&nbsp;&nbsp;A better idea might be to modify the ModifiedTime\r\n of&nbsp;each ZipEntry&nbsp;<em>before </em>extraction.&nbsp; One tweak to your approach is to use a self-extracting zip for extraction, and upon extraction automatically run a program (that's a feature of the SFX) that intelligently calculates the offset according\r\n to its current timezone, and resets the time of the already-unzipped files in the filesystem.&nbsp;\r\n</li></ol>\r\n</li><li>You can NOT store the times as UTC when you create the zip. The succintly named\r\n<a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/d5a61123-fc31-b747-6e50-0d25fa627a1f.htm\">\r\nZipFile.EmitTimesInWindowsFormatWhenSaving</a>&nbsp;property, when set to false, tells DotNetZip to NOT use UTC times.&nbsp; DotNetZip WILL store the DOS &nbsp;time for each entry, which will not include any timezone information.&nbsp;Set this property before\r\n adding any entries into the&nbsp;ZipFile. &nbsp;Therefore if your file has a 5am (localtime) timestamp when you zip in California, it will have a 5am (localtime) timestamp when you unzip in New York.&nbsp; If you do this, you will get a lower precision time\r\n (accurate to 2 seconds) in addition to losing the timezone information. </li></ol>\r\n<p>&nbsp;</p>\r\n<ol>\r\n</ol>\r\n",
    "PostedDate": "2010-11-24T12:11:32.623-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]