0

Windows stores FileTime internally as the number of 100-nanoseconds since 1.1.1601 UTC as a 64bit field, is it possible to get java to print out the current number? Just looking for an example as I can't find a way to do it. I would like to print the number out?

Any help woudl be greatful!

Thanks.

2
  • what is the problem here? to get the file, to read it, or to print? Commented Mar 4, 2011 at 21:29
  • Did you take a look at the following thread on this site? [stackoverflow.com/questions/32586/… Is that what you're after or there is something else? Commented Mar 4, 2011 at 21:40

2 Answers 2

0

Approximately

long diff1601to1970 = 315532800 * 1000000000; // <-- diff in nanoseconds(1/1/1601 to 1/1/1970)
long currentFrom1970 =  System.currentTimeMillis() * 1000000;
long currentFrom1601 = diff1601to1970 + currentFrom1970;
Sign up to request clarification or add additional context in comments.

Comments

0

Java doesn't provide direct access to a raw file time, so if you ask for the lastModified time

someFile.lastModified();

You will get the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs

Not every platform tracks the "same" times in relation to a file, and how they track it internally is different. Part of Java's attempt to make a coherent platform out of the differing standards uses polymorphism to translate the platform specific times to the "java standard" under the covers.

Now to convert the millis returned to a java time:

java.util.Date date = new java.util.Date(millis);

From there you can use the standard i/o routines to display and format the date (DateFormat, etc.)

PS. 1/1/1601 was chosen as the epoch by COBOL initially and mimicked by Microsoft (and possibly others). The reason it was chosen is because it's the start of the 400 year Gregorian Calendar cycle at the time the operating system was released. Every 400 years, the pattern of leap years repeats itself.

1 Comment

Even if you decide to attempt to "back calculate" the approximate WINTIME date, you can't assure that it's the right time, as Java's finest unit of measurement is a millisecond, while WINTIME's finest unit of measurement is smaller. Information was lost in the conversion to the java epoch standard, in this case it was lost in the dropping of the fractional portion of the file's perceptional milliseconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.