APIdia Launch Partner
Top Description Fields Constructors Methods
java.nio.file.attribute

public final Class FileTime

extends Object
implements Comparable<FileTime>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.time.Instant, .LocalDateTime, .ZoneOffset, java.util.Objects, java.util.concurrent.TimeUnit

Represents the value of a file's time stamp attribute. For example, it may represent the time that the file was last modified, accessed, or created.

Instances of this class are immutable.

Since
1.7
See Also
java.nio.file.Files#setLastModifiedTime, java.nio.file.Files#getLastModifiedTime

Field Summary

Modifier and TypeField and Description
private static final long
private static final long
HOURS_PER_DAY

Time unit constants for conversion.

private Instant
instant

The value as Instant (created lazily, if not from an instant)

private static final long
private static final long
private static final long
private static final long
private static final long
private static final int
private static final int
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private final TimeUnit
unit

The unit of granularity to interpret the value.

private final long
value

The value since the epoch; can be negative.

private String
valueAsString

The value return by toString (created lazily)

Constructor Summary

AccessConstructor and Description
private
FileTime(long value, TimeUnit unit, Instant instant)

Initializes a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
private StringBuilder
append(StringBuilder sb, int w, int d)

public int

Returns:

0 if this FileTime is equal to other, a value less than 0 if this FileTime represents a time that is before other, and a value greater than 0 if this FileTime represents a time that is after other
compareTo
(FileTime
the other FileTime to be compared
other
)

Implements java.lang.Comparable.compareTo.

Compares the value of two FileTime objects for order.

public boolean

Returns:

true if, and only if, the given object is a FileTime that represents the same time
equals
(Object
the object to compare with
obj
)

Overrides java.lang.Object.equals.

Tests this FileTime for equality with the given object.

public static FileTime

Returns:

a FileTime representing the given value
from
(long
the value since the epoch (1970-01-01T00:00:00Z); can be negative
value
,
TimeUnit
the unit of granularity to interpret the value
unit
)

Returns a FileTime representing a value at the given unit of granularity.

public static FileTime

Returns:

a FileTime representing the same point on the time-line as the provided instant
from
(Instant
the instant to convert
instant
)

Returns a FileTime representing the same point of time value on the time-line as the provided Instant object.

public static FileTime

Returns:

a FileTime representing the given value
fromMillis
(long
the value, in milliseconds, since the epoch (1970-01-01T00:00:00Z); can be negative
value
)

Returns a FileTime representing the given value in milliseconds.

public int

Returns:

the hash-code value
hashCode
()

Overrides java.lang.Object.hashCode.

Computes a hash code for this file time.

private static long
scale(long d, long m, long over)

public long

Returns:

value in the given unit of granularity, since the epoch since the epoch (1970-01-01T00:00:00Z); can be negative
to
(TimeUnit
the unit of granularity for the return value
unit
)

Returns the value at the given unit of granularity.

private long
private long
toExcessNanos(long days)

public Instant

Returns:

an instant representing the same point on the time-line as this FileTime object
toInstant
()

Converts this FileTime object to an Instant.

public long

Returns:

the value in milliseconds, since the epoch (1970-01-01T00:00:00Z)
toMillis
()

Returns the value in milliseconds.

public String

Returns:

the string representation of this file time
toString
()

Overrides java.lang.Object.toString.

Returns the string representation of this FileTime.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DAYS_PER_10000_YEARSback to summary
private static final long DAYS_PER_10000_YEARS
HOURS_PER_DAYback to summary
private static final long HOURS_PER_DAY

Time unit constants for conversion.

instantback to summary
private Instant instant

The value as Instant (created lazily, if not from an instant)

MAX_SECONDback to summary
private static final long MAX_SECOND
MICROS_PER_SECONDback to summary
private static final long MICROS_PER_SECOND
MILLIS_PER_SECONDback to summary
private static final long MILLIS_PER_SECOND
MIN_SECONDback to summary
private static final long MIN_SECOND
MINUTES_PER_HOURback to summary
private static final long MINUTES_PER_HOUR
NANOS_PER_MICROback to summary
private static final int NANOS_PER_MICRO
NANOS_PER_MILLIback to summary
private static final int NANOS_PER_MILLI
NANOS_PER_SECONDback to summary
private static final long NANOS_PER_SECOND
SECONDS_0000_TO_1970back to summary
private static final long SECONDS_0000_TO_1970
SECONDS_PER_10000_YEARSback to summary
private static final long SECONDS_PER_10000_YEARS
SECONDS_PER_DAYback to summary
private static final long SECONDS_PER_DAY
SECONDS_PER_HOURback to summary
private static final long SECONDS_PER_HOUR
SECONDS_PER_MINUTEback to summary
private static final long SECONDS_PER_MINUTE
unitback to summary
private final TimeUnit unit

The unit of granularity to interpret the value. Null if this FileTime is converted from an Instant, the value and unit pair will not be used in this scenario.

valueback to summary
private final long value

The value since the epoch; can be negative.

valueAsStringback to summary
private String valueAsString

The value return by toString (created lazily)

Constructor Detail

FileTimeback to summary
private FileTime(long value, TimeUnit unit, Instant instant)

Initializes a new instance of this class.

Method Detail

appendback to summary
private StringBuilder append(StringBuilder sb, int w, int d)
compareToback to summary
public int compareTo(FileTime other)

Implements java.lang.Comparable.compareTo.

Compares the value of two FileTime objects for order.

Parameters
other:FileTime

the other FileTime to be compared

Returns:int

0 if this FileTime is equal to other, a value less than 0 if this FileTime represents a time that is before other, and a value greater than 0 if this FileTime represents a time that is after other

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Tests this FileTime for equality with the given object.

The result is true if and only if the argument is not null and is a FileTime that represents the same time. This method satisfies the general contract of the Object.equals method.

Parameters
obj:Object

the object to compare with

Returns:boolean

true if, and only if, the given object is a FileTime that represents the same time

Annotations
@Override
fromback to summary
public static FileTime from(long value, TimeUnit unit)

Returns a FileTime representing a value at the given unit of granularity.

Parameters
value:long

the value since the epoch (1970-01-01T00:00:00Z); can be negative

unit:TimeUnit

the unit of granularity to interpret the value

Returns:FileTime

a FileTime representing the given value

fromback to summary
public static FileTime from(Instant instant)

Returns a FileTime representing the same point of time value on the time-line as the provided Instant object.

Parameters
instant:Instant

the instant to convert

Returns:FileTime

a FileTime representing the same point on the time-line as the provided instant

Since
1.8
fromMillisback to summary
public static FileTime fromMillis(long value)

Returns a FileTime representing the given value in milliseconds.

Parameters
value:long

the value, in milliseconds, since the epoch (1970-01-01T00:00:00Z); can be negative

Returns:FileTime

a FileTime representing the given value

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Computes a hash code for this file time.

The hash code is based upon the value represented, and satisfies the general contract of the Object#hashCode method.

Returns:int

the hash-code value

Annotations
@Override
scaleback to summary
private static long scale(long d, long m, long over)
toback to summary
public long to(TimeUnit unit)

Returns the value at the given unit of granularity.

Conversion from a coarser granularity that would numerically overflow saturate to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive.

Parameters
unit:TimeUnit

the unit of granularity for the return value

Returns:long

value in the given unit of granularity, since the epoch since the epoch (1970-01-01T00:00:00Z); can be negative

toDaysback to summary
private long toDays()
toExcessNanosback to summary
private long toExcessNanos(long days)
toInstantback to summary
public Instant toInstant()

Converts this FileTime object to an Instant.

The conversion creates an Instant that represents the same point on the time-line as this FileTime.

FileTime can store points on the time-line further in the future and further in the past than Instant. Conversion from such further time points saturates to Instant#MIN if earlier than Instant.MIN or Instant#MAX if later than Instant.MAX.

Returns:Instant

an instant representing the same point on the time-line as this FileTime object

Since
1.8
toMillisback to summary
public long toMillis()

Returns the value in milliseconds.

Conversion from a coarser granularity that would numerically overflow saturate to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive.

Returns:long

the value in milliseconds, since the epoch (1970-01-01T00:00:00Z)

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the string representation of this FileTime. The string is returned in the ISO 8601 format:

    YYYY-MM-DDThh:mm:ss[.s+]Z
where "[.s+]" represents a dot followed by one of more digits for the decimal fraction of a second. It is only present when the decimal fraction of a second is not zero. For example, FileTime.fromMillis(1234567890000L).toString() yields "2009-02-13T23:31:30Z", and FileTime.fromMillis(1234567890123L).toString() yields "2009-02-13T23:31:30.123Z".

A FileTime is primarily intended to represent the value of a file's time stamp. Where used to represent extreme values, where the year is less than "0001" or greater than "9999" then this method deviates from ISO 8601 in the same manner as the XML Schema language. That is, the year may be expanded to more than four digits and may be negative-signed. If more than four digits then leading zeros are not present. The year before "0001" is "-0001".

Returns:String

the string representation of this file time

Annotations
@Override
External Specification
https://www.w3.org/TR/NOTE-datetime, https://www.w3.org/TR/xmlschema-2