java creation date code example
Example 1: java get creation date of file
Path file = ...;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
Example 2: how to create date class in java
// This creates a new Date instance with current system time. Internally It uses System.currentTimeMillis()
Date date = new Date();
// This creates a new Date instance with time that you specify in milliseconds since the epoch time
Date date = new Date(1672556400000L); // This time is Jan 1 2023 in GMT