File Modified Date in Java

I set the modification date of the file created in Java to a specific number. When I read this value on Windows, I get the same value. However, on Linux (ubuntu), I get a different value. The value for File.lastModified () is disabled for 9 hours, but when I look at the properties of the file, I see that it is disabled for only 1 hour. I expect the same value in all directions.

Am I wrong to rely on compatibility and consistency? javadoc is fairly straightforward in terms of the method and does not mention potential incompatibilities.

+4
source share
3 answers

This is almost certainly a time zone problem. The Java method uses / expects GMT, the OS will display local time, which explains the difference. Now the real question is: how is time stored in the file system?

What file system are you using? Probably FAT32, which stores timestamps in local time, which makes it difficult to coordinate them between the OS. I'm not sure where exactly everything goes wrong, but it could be an OS configuration problem or a JVM error - which JVM do you use on Linux?

+3
source

have you checked the return value of setLastModified ?

Return:

 true if and only if the operation succeeded; false otherwise 
0
source

I assume this is a timezone issue. Please note that javadoc says "milliseconds from the era (00:00:00 GMT , January 1, 1970") (emphasis added). Is it possible that the value you passed to setModified was milliseconds from an epoch, local time? If so, then you will be one hour with local time in Belgium GMT + 1. This explains the time in the properties dialog box.

I find it difficult to explain the 9 hour difference from lastModified () if java or os somehow cache the old value.

0
source

All Articles