Added in API level 26

FileTime

class FileTime : Comparable<FileTime!>
kotlin.Any
   ↳ java.nio.file.attribute.FileTime

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.

Summary

Public methods
Int

Compares the value of two FileTime objects for order.

Boolean
equals(other: Any?)

Tests this FileTime for equality with the given object.

static FileTime!
from(value: Long, unit: TimeUnit!)

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

static FileTime!
from(instant: Instant!)

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

static FileTime!
fromMillis(value: Long)

Returns a FileTime representing the given value in milliseconds.

Int

Computes a hash code for this file time.

Long
to(unit: TimeUnit!)

Returns the value at the given unit of granularity.

Instant!

Converts this FileTime object to an Instant.

Long

Returns the value in milliseconds.

String

Returns the string representation of this FileTime.

Public methods

compareTo

Added in API level 26
fun compareTo(other: FileTime!): Int

Compares the value of two FileTime objects for order.

Parameters
o the object to be compared.
other FileTime!: the other FileTime to be compared
Return
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
Exceptions
java.lang.NullPointerException if the specified object is null
java.lang.ClassCastException if the specified object's type prevents it from being compared to this object.

equals

Added in API level 26
fun equals(other: Any?): Boolean

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 the object to compare with
Return
Boolean true if, and only if, the given object is a FileTime that represents the same time

from

Added in API level 26
static fun from(
    value: Long,
    unit: TimeUnit!
): FileTime!

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
Return
FileTime! a FileTime representing the given value

from

Added in API level 26
static fun from(instant: Instant!): FileTime!

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
Return
FileTime! a FileTime representing the same point on the time-line as the provided instant

fromMillis

Added in API level 26
static fun fromMillis(value: Long): FileTime!

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
Return
FileTime! a FileTime representing the given value

hashCode

Added in API level 26
fun hashCode(): Int

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.

Return
Int the hash-code value

to

Added in API level 26
fun to(unit: TimeUnit!): Long

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
Return
Long value in the given unit of granularity, since the epoch since the epoch (1970-01-01T00:00:00Z); can be negative

toInstant

Added in API level 26
fun toInstant(): Instant!

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.

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

toMillis

Added in API level 26
fun toMillis(): Long

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.

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

toString

Added in API level 26
fun toString(): String

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".

Return
String the string representation of this file time