# FileTime

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/java/nio/file/attribute/FileTime#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/nio/file/attribute/FileTime#inhmethods)  

# FileTime

`
public

final

class
FileTime
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Comparable](https://developer.android.com/reference/java/lang/Comparable)`<`[FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime)`>


`

|---|----------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.nio.file.attribute.FileTime |

<br />

*** ** * ** ***

Represents the value of a file's time stamp attribute. For example, it may represent the time that the file was last[modified](https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributes#lastModifiedTime()),[accessed](https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributes#lastAccessTime()), or[created](https://developer.android.com/reference/java/nio/file/attribute/BasicFileAttributes#creationTime()).

Instances of this class are immutable.  
**See also:**

- [Files.setLastModifiedTime(Path, FileTime)](https://developer.android.com/reference/java/nio/file/Files#setLastModifiedTime(java.nio.file.Path,%20java.nio.file.attribute.FileTime))
- [Files.getLastModifiedTime(Path, LinkOption)](https://developer.android.com/reference/java/nio/file/Files#getLastModifiedTime(java.nio.file.Path,%20java.nio.file.LinkOption[]))

## Summary

|                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                 ||
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`                                                                                         | ` `[compareTo](https://developer.android.com/reference/java/nio/file/attribute/FileTime#compareTo(java.nio.file.attribute.FileTime))`(`[FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime)` other) ` Compares the value of two`FileTime`objects for order.                        |
| ` boolean`                                                                                     | ` `[equals](https://developer.android.com/reference/java/nio/file/attribute/FileTime#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Tests this`FileTime`for equality with the given object.                                                                |
| ` static `[FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime) | ` `[from](https://developer.android.com/reference/java/nio/file/attribute/FileTime#from(java.time.Instant))`(`[Instant](https://developer.android.com/reference/java/time/Instant)` instant) ` Returns a`FileTime`representing the same point of time value on the time-line as the provided`Instant`object.       |
| ` static `[FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime) | ` `[from](https://developer.android.com/reference/java/nio/file/attribute/FileTime#from(long,%20java.util.concurrent.TimeUnit))`(long value, `[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit)` unit) ` Returns a`FileTime`representing a value at the given unit of granularity. |
| ` static `[FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime) | ` `[fromMillis](https://developer.android.com/reference/java/nio/file/attribute/FileTime#fromMillis(long))`(long value) ` Returns a`FileTime`representing the given value in milliseconds.                                                                                                                         |
| ` int`                                                                                         | ` `[hashCode](https://developer.android.com/reference/java/nio/file/attribute/FileTime#hashCode())`() ` Computes a hash code for this file time.                                                                                                                                                                   |
| ` long`                                                                                        | ` `[to](https://developer.android.com/reference/java/nio/file/attribute/FileTime#to(java.util.concurrent.TimeUnit))`(`[TimeUnit](https://developer.android.com/reference/java/util/concurrent/TimeUnit)` unit) ` Returns the value at the given unit of granularity.                                               |
| ` `[Instant](https://developer.android.com/reference/java/time/Instant)                        | ` `[toInstant](https://developer.android.com/reference/java/nio/file/attribute/FileTime#toInstant())`() ` Converts this`FileTime`object to an`Instant`.                                                                                                                                                            |
| ` long`                                                                                        | ` `[toMillis](https://developer.android.com/reference/java/nio/file/attribute/FileTime#toMillis())`() ` Returns the value in milliseconds.                                                                                                                                                                         |
| ` `[String](https://developer.android.com/reference/java/lang/String)                          | ` `[toString](https://developer.android.com/reference/java/nio/file/attribute/FileTime#toString())`() ` Returns the string representation of this`FileTime`.                                                                                                                                                       |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.lang.Comparable](https://developer.android.com/reference/java/lang/Comparable)` ` |-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract int` | ` `[compareTo](https://developer.android.com/reference/java/lang/Comparable#compareTo(T))`(`[FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime)` o) ` Compares this object with the specified object for order. | ||

## Public methods

### compareTo

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int compareTo (FileTime other)
```

Compares the value of two`FileTime`objects for order.

<br />

|                          Parameters                           ||
|---------|------------------------------------------------------|
| `other` | `FileTime`: the other`FileTime`to be compared <br /> |

|                                                                                                        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` <br /> |

### equals

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean equals (Object obj)
```

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.

<br />

|                     Parameters                     ||
|-------|---------------------------------------------|
| `obj` | `Object`: the object to compare with <br /> |

|                                                Returns                                                ||
|-----------|--------------------------------------------------------------------------------------------|
| `boolean` | `true`if, and only if, the given object is a`FileTime`that represents the same time <br /> |

### from

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

|                     Parameters                      ||
|-----------|------------------------------------------|
| `instant` | `Instant`: the instant to convert <br /> |

|                                                                                   Returns                                                                                    ||
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime) | a`FileTime`representing the same point on the time-line as the provided instant <br /> |

### from

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static FileTime from (long value, 
                TimeUnit unit)
```

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

<br />

|                                        Parameters                                         ||
|---------|----------------------------------------------------------------------------------|
| `value` | `long`: the value since the epoch (1970-01-01T00:00:00Z); can be negative <br /> |
| `unit`  | `TimeUnit`: the unit of granularity to interpret the value <br />                |

|                                                               Returns                                                                ||
|--------------------------------------------------------------------------------------|------------------------------------------------|
| [FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime) | a`FileTime`representing the given value <br /> |

### fromMillis

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static FileTime fromMillis (long value)
```

Returns a`FileTime`representing the given value in milliseconds.

<br />

|                                                 Parameters                                                  ||
|---------|----------------------------------------------------------------------------------------------------|
| `value` | `long`: the value, in milliseconds, since the epoch (1970-01-01T00:00:00Z); can be negative <br /> |

|                                                               Returns                                                                ||
|--------------------------------------------------------------------------------------|------------------------------------------------|
| [FileTime](https://developer.android.com/reference/java/nio/file/attribute/FileTime) | a`FileTime`representing the given value <br /> |

### hashCode

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int 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](https://developer.android.com/reference/java/lang/Object#hashCode())method.

<br />

|              Returns              ||
|-------|----------------------------|
| `int` | the hash-code value <br /> |

### to

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

|                               Parameters                                ||
|--------|-----------------------------------------------------------------|
| `unit` | `TimeUnit`: the unit of granularity for the return value <br /> |

|                                                            Returns                                                             ||
|--------|------------------------------------------------------------------------------------------------------------------------|
| `long` | value in the given unit of granularity, since the epoch since the epoch (1970-01-01T00:00:00Z); can be negative <br /> |

### toInstant

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/java/time/Instant#MIN)if earlier than`Instant.MIN`or[Instant.MAX](https://developer.android.com/reference/java/time/Instant#MAX)if later than`Instant.MAX`.

<br />

|                                                                           Returns                                                                            ||
|----------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [Instant](https://developer.android.com/reference/java/time/Instant) | an instant representing the same point on the time-line as this`FileTime`object <br /> |

### toMillis

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

|                                     Returns                                      ||
|--------|--------------------------------------------------------------------------|
| `long` | the value in milliseconds, since the epoch (1970-01-01T00:00:00Z) <br /> |

### toString

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Returns the string representation of this`FileTime`. The string is returned in the[ISO 8601](http://www.w3.org/TR/NOTE-datetime)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](http://www.w3.org/TR/xmlschema-2/#deviantformats). 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`".

<br />

|                                                        Returns                                                         ||
|--------------------------------------------------------------------|----------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the string representation of this file time <br /> |