setting time on Zip Entry
-
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 -
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, ElenaApparently, 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
-
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, ElenaDateTime
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'sDate
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 aDateTime
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 thejava.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
-
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
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. TheDateTime
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
-
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'sDate
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 aDateTime
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 thejava.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
Is java.util.Date a part of vjslib or is it from a different library? Thanks for your help. Elena
-
Is java.util.Date a part of vjslib or is it from a different library? Thanks for your help. Elena
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
-
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. TheDateTime
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
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...
-
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...
The didn't. The
java.util.Date
is nothing like theDateTime
. The J# portability assemblies work just like the Java classes. Encapsulating aDateTime
in aDate
, for example, would screw-up any code that modifies theDate
.Microsoft MVP, Visual C# My Articles