File timestamp precision on Linux?
Xueming Shen
xueming.shen at oracle.com
Mon Jun 9 17:51:23 UTC 2014
On 06/08/2014 11:42 PM, Alan Bateman wrote:
> On 09/06/2014 00:57, Zhong Yu wrote:
>> Apparently, Java8 reports Linux file timestamps only in SECOND
>> precision? Am I doing something wrong?
>>
>> Java version:
>>
>> java version "1.8.0_20-ea"
>> Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b17)
>> Java HotSpot(TM) 64-Bit Server VM (build 25.20-b17, mixed mode)
>>
>> Linux version:
>> Linux 3.10.40-50.136.amzn1.x86_64 x86_64
>> (an amazon aws micro instance)
> It supports higher precision timestamps too. Can you run locally and print out the value of "time"? I wonder if the issue is AWS or something else (like toInstant)
>
> -Alan
>
>
Instant now = Instant.now();
FileTime nowFT = FileTime.from(now);
System.out.println(" Instant.now():" + now);
System.out.println("FileTime.from(Instant.now).toInstant():" + nowFT.toInstant());
Files.setLastModifiedTime(filePath, nowFT);
BasicFileAttributes attrs = Files.readAttributes(filePath, BasicFileAttributes.class);
FileTime time = attrs.lastModifiedTime();
System.out.println();
System.out.println(" ft:" + time.toInstant());
System.out.println("ins:" + time.toInstant());
-->
Instant.now():2014-06-09T17:49:45.795Z
FileTime.from(Instant.now).toInstant():2014-06-09T17:49:45.795Z
ft:2014-06-09T17:49:45Z
ins:2014-06-09T17:49:45Z
So, something else is not likely to be "toInstant" :-)
-Sherman
More information about the nio-dev
mailing list