问题
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.
回答1:
Approximately
long diff1601to1970 = 315532800 * 1000000000; // <-- diff in nanoseconds(1/1/1601 to 1/1/1970)
long currentFrom1970 = System.currentTimeMillis() * 1000000;
long currentFrom1601 = diff1601to1970 + currentFrom1970;
回答2:
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.
来源:https://stackoverflow.com/questions/5199478/java-display-windows-utc-time