java.nio.file.attribute.FileTime Class in Java Last Updated : 28 Mar, 2022 Comments Improve Suggest changes Like Article Like Report The java.nio.file.attribute.FileTime class is used to get a value representing this file's timestamp i.e, the time when this file was last modified, accessed, or created. Class Declaration: public final class FileTime extends Object implements Comparable<FileTime>Methods: MethodDescriptioncompareTo(FileTime other)This method compares the value of two FileTime objects for the order.equals(Object obj)This method tests this FileTime for equality with the given object.from(Instant instant)This method returns a FileTime representing the same point of time value on the time-line as the provided Instant object.from(long value, TimeUnit unit)This method returns a FileTime representing a value at the given unit of granularity.fromMillis(long value)This method returns a FileTime representing the given value in milliseconds.hashCode()This method computes a hash code for this file time.to(TimeUnit unit)This method returns the value at the given unit of granularity.toInstant()This method converts this FileTime object to an Instant.toMillis()This method returns the value in milliseconds.toString()This method returns the string representation of this FileTime.Below is the implementation of some methods from java.nio.file.attribute.FileTime class in java: Java import java.nio.file.attribute.FileTime; import java.time.Instant; import java.util.concurrent.TimeUnit; public class GFG { public static void main(String[] args) { // Variables for storing time values long v1 = 21; long v2 = 356; // Creating an Instant. Instant instant = Instant.parse("2017-02-03T10:37:30.00Z"); // Creating FileTime object using from // Method This method takes an Integer // value and a timeunit as parameters. FileTime filetime2 = FileTime.from(v2, TimeUnit.MILLISECONDS); // Creating FileTime object using fromMillis method. FileTime filetime1 = FileTime.fromMillis(v1); // Creating FileTime object using from Method // This method takes an Instant as parameters. FileTime filetime3 = FileTime.from(instant); // Method to convert this filetime to an instant. Instant instantFromFileTime = filetime3.toInstant(); // Method to convert filetime1 to this timeunit. System.out.println( filetime1.to(TimeUnit.MILLISECONDS)); // Method to check if filetime1 // is equal to filetime2 or not. if (filetime1.equals(filetime2)) System.out.println("FileTime are equal"); else System.out.println("FileTime are not equal"); // Method to print hashvalue of filetime1. System.out.println(filetime1.hashCode()); // Method to convert filetime1 to milliseconds. System.out.println(filetime1.toMillis()); // Method to compare filetime1 and filetime2. System.out.println(filetime1.compareTo(filetime2)); // Method to print string // representation of filetime1. System.out.println(filetime1.toString()); } } Output21 FileTime are not equal 1071000000 21 -1 1970-01-01T00:00:00.021Z Comment More infoAdvertise with us Next Article java.nio.file.Paths Class in Java A abhinavjain194 Follow Improve Article Tags : Java Java-NIO package Practice Tags : Java Similar Reads java.nio.file.FileStore Class in Java Java.nio.file is a package in java that consists of the FileStore class. FileStore class is a class that provides methods for the purpose of performing some operations on file store. FileStore is a class that extends Object from java.lang package. And few methods the FileStore class can inherit from 4 min read java.nio.file.FileSystem class in java java.nio.file.FileSystem class provides an interface to a file system. The file system acts as a factory for creating different objects like Path, PathMatcher, UserPrincipalLookupService, and WatchService. This object help to access the files and other objects in the file system. Syntax: Class decla 4 min read java.nio.file.attribute.AclEntry Class in Java ACL entries are Examined by this class is validating on the ACL model declared in RFC 3530: Network File System i.e.(NFS) version of 4th Protocol and having four components within it as follows characteristics as follows:Â This type of component are determining if the entry grants or denies its acce 3 min read java.nio.file.spi.FileTypeDetector Class in Java java.nio.file.spi.FileTypeDetector Class extends java.lang.Object Class. FileTypeDetector Class contain method to know about the content type of given file. Class declaration: public abstract class FileTypeDetector extends ObjectConstructor: ConstructorDescriptionprotected FileTypeDetector()It is us 2 min read java.nio.file.Paths Class in Java java.nio.file.Paths class contains static methods for converting path string or URI into Path. Class declaration : public final class Paths extends ObjectMethods: MethodDescriptionget(String first, String... more) This method converts a path string, or a sequence of strings that when joined form a p 2 min read java.time.Instant Class in Java In Java language, the Instant Class is used to represent the specific time instant on the current timeline. The Instant Class extends the Object Class and implements the Comparable interface. Declaration of the Instant Class public final class Instant extends Object implements Temporal, TemporalAdju 4 min read Like