File timestamp precision on Linux?
Xueming Shen
xueming.shen at oracle.com
Mon Jun 9 18:13:03 UTC 2014
On 06/09/2014 10:51 AM, Xueming Shen wrote:
> 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
oh, to be clear, I'm on a 32-bit linux, so the system stat probably works for a second precision.
-Sherman
More information about the nio-dev
mailing list