Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. setting time on Zip Entry

setting time on Zip Entry

Scheduled Pinned Locked Moved C#
javaquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elena12345
    wrote on last edited by
    #1

    I am zipping up a bunch of files and "Modified" date on the files always turns out to be 1/1/1980 12:00AM The date I have is in DateTime format, and I tried zipEntry.setDate(d.ToFileTimeUtc()) zipEntry.setDate(d.ToFileTimeUtc()) zipEntry.setDate(d.ToFileTime()) zipEntry.setDate(d.Ticks) Nothing works!!! It keeps on getting 1/1/1980 12:00AM Do you have any idea why this is not working? Code: ZipEntry currententry = new ZipEntry(localPath); currententry.setMethod(ZipEntry.DEFLATED); currententry.setTime(createDate.ToFileTimeUtc()); m_zipstream.putNextEntry(currententry); try { java.io.FileInputStream current = new java.io.FileInputStream(fullPath); try { sbyte[] buffer = new sbyte[8192]; int buffercount; while ((buffercount = current.read(buffer, 0, buffer.Length)) > 0) m_zipstream.write(buffer, 0, buffercount); } finally { current.close(); } } finally { m_zipstream.closeEntry(); } Thanks, Elena

    J H 2 Replies Last reply
    0
    • E elena12345

      I am zipping up a bunch of files and "Modified" date on the files always turns out to be 1/1/1980 12:00AM The date I have is in DateTime format, and I tried zipEntry.setDate(d.ToFileTimeUtc()) zipEntry.setDate(d.ToFileTimeUtc()) zipEntry.setDate(d.ToFileTime()) zipEntry.setDate(d.Ticks) Nothing works!!! It keeps on getting 1/1/1980 12:00AM Do you have any idea why this is not working? Code: ZipEntry currententry = new ZipEntry(localPath); currententry.setMethod(ZipEntry.DEFLATED); currententry.setTime(createDate.ToFileTimeUtc()); m_zipstream.putNextEntry(currententry); try { java.io.FileInputStream current = new java.io.FileInputStream(fullPath); try { sbyte[] buffer = new sbyte[8192]; int buffercount; while ((buffercount = current.read(buffer, 0, buffer.Length)) > 0) m_zipstream.write(buffer, 0, buffercount); } finally { current.close(); } } finally { m_zipstream.closeEntry(); } Thanks, Elena

      J Offline
      J Offline
      Jeff Varszegi
      wrote on last edited by
      #2

      Apparently, there are bugs in the J# zip library; check out this recent post by Nish: Bug when using the java.util.zip classes to write zip files Several people recommended SharpZipLib, about which I've also heard good things. -Jeff

      H 1 Reply Last reply
      0
      • E elena12345

        I am zipping up a bunch of files and "Modified" date on the files always turns out to be 1/1/1980 12:00AM The date I have is in DateTime format, and I tried zipEntry.setDate(d.ToFileTimeUtc()) zipEntry.setDate(d.ToFileTimeUtc()) zipEntry.setDate(d.ToFileTime()) zipEntry.setDate(d.Ticks) Nothing works!!! It keeps on getting 1/1/1980 12:00AM Do you have any idea why this is not working? Code: ZipEntry currententry = new ZipEntry(localPath); currententry.setMethod(ZipEntry.DEFLATED); currententry.setTime(createDate.ToFileTimeUtc()); m_zipstream.putNextEntry(currententry); try { java.io.FileInputStream current = new java.io.FileInputStream(fullPath); try { sbyte[] buffer = new sbyte[8192]; int buffercount; while ((buffercount = current.read(buffer, 0, buffer.Length)) > 0) m_zipstream.write(buffer, 0, buffercount); } finally { current.close(); } } finally { m_zipstream.closeEntry(); } Thanks, Elena

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        DateTime in .NET and the date and time in Java use different epochs (start times). DateTime is the number of ticks from 00:00:00 Jan. 1, 0001 AD. Java's Date starts at 00:00:00 Jan. 1, 1970 AD and is the number of milliseconds from that date/time. A tick is 100 nanoseconds. So, to convert a DateTime to the number of milliseconds to use, you'll need to take this information into account and convert the number. The best way is to use the java.util.Date class. When working with the vjslib.dll assembly, keep in mind that this assembly exists only to make it easier for Java developers to make the move. It's intended to work just like it would if you were still developing with Java classes. Classes in the FCL and Java assemblies should not be inter-mixed without proper consideration.

        Microsoft MVP, Visual C# My Articles

        E 1 Reply Last reply
        0
        • J Jeff Varszegi

          Apparently, there are bugs in the J# zip library; check out this recent post by Nish: Bug when using the java.util.zip classes to write zip files Several people recommended SharpZipLib, about which I've also heard good things. -Jeff

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          I've heard that too (and I see I'm mentioned :-O). In this case, however, is sounds like an epoch problem since Java and .NET (not to mention the OLE DATE and who knows what else) all use different epochs. The DateTime struct in .NET also uses ticks (100 ns) instead of ms like most structs. And developers thought all the different text encodings were a problem! :rolleyes:

          Microsoft MVP, Visual C# My Articles

          J 1 Reply Last reply
          0
          • H Heath Stewart

            DateTime in .NET and the date and time in Java use different epochs (start times). DateTime is the number of ticks from 00:00:00 Jan. 1, 0001 AD. Java's Date starts at 00:00:00 Jan. 1, 1970 AD and is the number of milliseconds from that date/time. A tick is 100 nanoseconds. So, to convert a DateTime to the number of milliseconds to use, you'll need to take this information into account and convert the number. The best way is to use the java.util.Date class. When working with the vjslib.dll assembly, keep in mind that this assembly exists only to make it easier for Java developers to make the move. It's intended to work just like it would if you were still developing with Java classes. Classes in the FCL and Java assemblies should not be inter-mixed without proper consideration.

            Microsoft MVP, Visual C# My Articles

            E Offline
            E Offline
            elena12345
            wrote on last edited by
            #5

            Is java.util.Date a part of vjslib or is it from a different library? Thanks for your help. Elena

            H 1 Reply Last reply
            0
            • E elena12345

              Is java.util.Date a part of vjslib or is it from a different library? Thanks for your help. Elena

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              Yes it's in the vjslib.dll assembly, along with pretty much everything else you'd find in the JRE (besides the swing stuff). If you want to know for sure, run ildasm.exe (the IL Disassembler found in the .NET Framework SDK bin directory) and open the vjslib.dll assembly in the %WINDIR%\Microsoft.NET\Framework\v1.1.4322 directory. This will show you the assembly and Type metadata, as well as the IL for any module(s) in the assembly (if you know how to read IL).

              Microsoft MVP, Visual C# My Articles

              1 Reply Last reply
              0
              • H Heath Stewart

                I've heard that too (and I see I'm mentioned :-O). In this case, however, is sounds like an epoch problem since Java and .NET (not to mention the OLE DATE and who knows what else) all use different epochs. The DateTime struct in .NET also uses ticks (100 ns) instead of ms like most structs. And developers thought all the different text encodings were a problem! :rolleyes:

                Microsoft MVP, Visual C# My Articles

                J Offline
                J Offline
                Jeff Varszegi
                wrote on last edited by
                #7

                I never even used J#, but you could be right. I didn't know that they actually replicated the Java classes like DateTime that have equivalents in C#, but it does make sense. In any case, the poster'd probably be MUCH better off using SharpZipLib...

                H 1 Reply Last reply
                0
                • J Jeff Varszegi

                  I never even used J#, but you could be right. I didn't know that they actually replicated the Java classes like DateTime that have equivalents in C#, but it does make sense. In any case, the poster'd probably be MUCH better off using SharpZipLib...

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  The didn't. The java.util.Date is nothing like the DateTime. The J# portability assemblies work just like the Java classes. Encapsulating a DateTime in a Date, for example, would screw-up any code that modifies the Date.

                  Microsoft MVP, Visual C# My Articles

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups