Created
July 2, 2018 13:07
-
-
Save Sam-Kruglov/317f2c7ecee1e74c0456254c605563a3 to your computer and use it in GitHub Desktop.
Check reading the last modified time from a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileTimeChecker{ | |
public static void main(String[] args) throws IOException, URISyntaxException { | |
Path path = Files.write(Paths.get("/hey.txt"), "hey".getBytes()); | |
File file = new File("/hey.txt"); | |
Instant fileInstant = Instant.ofEpochMilli(file.lastModified()); | |
System.out.println("fileInstant: " + fileInstant); | |
Instant nioInstant = Files.getLastModifiedTime(path).toInstant(); | |
System.out.println("nioInstant: " + nioInstant); | |
ZonedDateTime fileTimeUtc = fileInstant.atZone(ZoneId.of("UTC")); | |
System.out.println("fileTimeUtc: " + fileTimeUtc); | |
ZonedDateTime nioTimeUtc = nioInstant.atZone(ZoneId.of("UTC")); | |
System.out.println("nioTimeUtc: " + nioTimeUtc); | |
ZonedDateTime fileTimeSystem = fileInstant.atZone(ZoneId.systemDefault()); | |
System.out.println("fileTimeSystem: " + fileTimeSystem); | |
ZonedDateTime nioTimeSystem = nioInstant.atZone(ZoneId.systemDefault()); | |
System.out.println("nioTimeSystem: " + nioTimeSystem); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produced the following output: