Molko
asked on
Java date object from a long
When i do the following
Date date = new Date(inputStream.readLong( ));
i get
[Mon Aug 04 10:20:00 BST 4093952]
it looks like the 'century' bit at the is not correct
Does java have an equivalent to c# - DateTime.FromFileTime(long val)
If not, how to i change my code to make work correctly.
Thanks
Date date = new Date(inputStream.readLong(
i get
[Mon Aug 04 10:20:00 BST 4093952]
it looks like the 'century' bit at the is not correct
Does java have an equivalent to c# - DateTime.FromFileTime(long
If not, how to i change my code to make work correctly.
Thanks
ASKER
if its any help the value from
inputStream.readLong() is 129130498200000000
inputStream.readLong() is 129130498200000000
ASKER
I think the Date should be 03/14/2010 14:17:00
The hex i am reading in is 00 56 E1 02 81 C3 CA 01
which i guess is
char hexData[8] = {
0x00, 0x56, 0xE1, 0x02, 0x81, 0xC3, 0xCA, 0x01
};
The hex i am reading in is 00 56 E1 02 81 C3 CA 01
which i guess is
char hexData[8] = {
0x00, 0x56, 0xE1, 0x02, 0x81, 0xC3, 0xCA, 0x01
};
> inputStream.readLong() is 129130498200000000
> I think the Date should be 03/14/2010 14:17:00
what makes you think that?
that value certainly isn't, where is the value coming from?
> I think the Date should be 03/14/2010 14:17:00
what makes you think that?
that value certainly isn't, where is the value coming from?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just a confirmation link or two (googled after posting because wanted to verify the date on which the .NET starts counting):
http://social.msdn.microsoft.com/Forums/en-US/visualjsharpgeneral/thread/e0bbfaf0-e261-425e-b13f-b270fbc1de21
http://msdn.microsoft.com/en-us/library/system.datetime.fromfiletime.aspx
So I guess that my memory about it was correct after all. :)
http://social.msdn.microsoft.com/Forums/en-US/visualjsharpgeneral/thread/e0bbfaf0-e261-425e-b13f-b270fbc1de21
http://msdn.microsoft.com/en-us/library/system.datetime.fromfiletime.aspx
So I guess that my memory about it was correct after all. :)
ASKER
Objects - Thanks, I know the date should be 03/14/2010 14:17:00 as the binary file I reading in had a list of dates relating to files on my PC. The files on my PC have the datetime as 03/14/2010 14:17:00.
Venabili - Thanks, that looks like a great lead, i'll read up on that now. Thanks again
Cheers guys !
Venabili - Thanks, that looks like a great lead, i'll read up on that now. Thanks again
Cheers guys !
:) Have fun - I think I had done it like this at least once (or it had been the opposite direction - cannot remember now) :)
Post back if you have issues and we will try to help.
Post back if you have issues and we will try to help.
ASKER
Hi
I think you were very much correct. I have done some research and the NanoSeconds/Milliseconds, 1601/1970 was exactly my problem.
long dateMs = inputStream.readLong(); //129130498200000000
System.out.println("Date in Nanos[" + dateMs + "]");
// Microsoft FileTime/Date Epoch is January 1, 1601
// Java Date Epoch is January 1, 1970, so take the number and subtract java Epoch:
dateMs = dateMs - 0x19db1ded53e8000L;
//convert UNITS from Nanoseconds(Microsoft) to Milliseconds (java)
dateMs /= 10000L;
System.out.println("Date in Ms[" + dateMs + "]");
Date date = new Date(dateMs);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yy yy HH:mm:ss");
String dateString = simpleDateFormat.format(da te);
System.out.println("Modifi edDate [" + dateString + "]");
And it give the correct result
I think you were very much correct. I have done some research and the NanoSeconds/Milliseconds, 1601/1970 was exactly my problem.
long dateMs = inputStream.readLong(); //129130498200000000
System.out.println("Date in Nanos[" + dateMs + "]");
// Microsoft FileTime/Date Epoch is January 1, 1601
// Java Date Epoch is January 1, 1970, so take the number and subtract java Epoch:
dateMs = dateMs - 0x19db1ded53e8000L;
//convert UNITS from Nanoseconds(Microsoft) to Milliseconds (java)
dateMs /= 10000L;
System.out.println("Date in Ms[" + dateMs + "]");
Date date = new Date(dateMs);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yy
String dateString = simpleDateFormat.format(da
System.out.println("Modifi
And it give the correct result
Yeah - why MS cannot play nicely and accept the Unix time is beyond me.
Do you need any more help here? :)
Do you need any more help here? :)
File file = ...// Initialize the file.
Date date = new Date(file.lastModified());