org.apache.commons.io.file.attribute

## Class FileTimes

- java.lang.Object
- - org.apache.commons.io.file.attribute.FileTimes

-     public final class FileTimes
      extends Object

  Helps use `FileTime` and interoperate Date and NTFS times.

  An NTFS file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). This is the offset of Windows time 0 to Unix epoch in 100-nanosecond intervals.

  See Also:
    NTFS File Times

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static FileTime` | `EPOCH` Constant for the `1970-01-01T00:00:00Z` `epoch` as a time stamp attribute.
    `(package private) static long` | `HUNDRED_NANOS_PER_MILLISECOND` The amount of 100-nanosecond intervals in one millisecond.
    `(package private) static BigDecimal` | `HUNDRED_NANOS_PER_MILLISECOND_BD`
    `(package private) static long` | `UNIX_TO_NTFS_OFFSET` The offset of Windows time 0 to Unix epoch in 100-nanosecond intervals.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static FileTime` | `fromUnixTime(long time)` Converts standard Unix time (in seconds, UTC/GMT) to `FileTime`.
    `static boolean` | `isUnixTime(FileTime time)` Tests whether a FileTime can be safely represented in the standard Unix time.
    `static boolean` | `isUnixTime(long seconds)` Tests whether a given number of seconds (since Epoch) can be safely represented in the standard Unix time.
    `static FileTime` | `minusMillis(FileTime fileTime, long millisToSubtract)` Subtracts milliseconds from a source FileTime.
    `static FileTime` | `minusNanos(FileTime fileTime, long nanosToSubtract)` Subtracts nanoseconds from a source FileTime.
    `static FileTime` | `minusSeconds(FileTime fileTime, long secondsToSubtract)` Subtracts seconds from a source FileTime.
    `static FileTime` | `now()` Obtains the current instant FileTime from the system clock.
    `(package private) static Date` | `ntfsTimeToDate(BigDecimal ntfsTime)`
    `static Date` | `ntfsTimeToDate(long ntfsTime)` Converts an NTFS time (100 nanosecond units since 1 January 1601) to a `Date`.
    `static FileTime` | `ntfsTimeToFileTime(long ntfsTime)` Converts an NTFS time (100-nanosecond units since 1 January 1601) to a `FileTime`.
    `(package private) static java.time.Instant` | `ntfsTimeToInstant(BigDecimal ntfsTime)`
    `(package private) static java.time.Instant` | `ntfsTimeToInstant(long ntfsTime)`
    `static FileTime` | `plusMillis(FileTime fileTime, long millisToAdd)` Adds milliseconds to a `FileTime`.
    `static FileTime` | `plusNanos(FileTime fileTime, long nanosToSubtract)` Adds nanoseconds to a `FileTime`.
    `static FileTime` | `plusSeconds(FileTime fileTime, long secondsToAdd)` Adds seconds to a `FileTime`.
    `static void` | `setLastModifiedTime(Path path)` Sets the last modified time of the given file path to now.
    `static Date` | `toDate(FileTime fileTime)` Converts a `FileTime` to a `Date`.
    `static FileTime` | `toFileTime(Date date)` Converts a `Date` to a `FileTime`.
    `static long` | `toNtfsTime(Date date)` Converts a `Date` to NTFS time.
    `static long` | `toNtfsTime(FileTime fileTime)` Converts a `FileTime` to NTFS time (100-nanosecond units since 1 January 1601).
    `(package private) static long` | `toNtfsTime(java.time.Instant instant)`
    `static long` | `toNtfsTime(long javaTime)` Converts a Java time (milliseconds since Epoch) to NTFS time.
    `static long` | `toUnixTime(FileTime fileTime)` Converts a `FileTime` to standard Unix time in seconds.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### EPOCH

          public static final FileTime EPOCH

      Constant for the `1970-01-01T00:00:00Z` `epoch` as a time stamp attribute.
      See Also:
        `Instant.EPOCH`

    - #### HUNDRED_NANOS_PER_MILLISECOND

          static final long HUNDRED_NANOS_PER_MILLISECOND

      The amount of 100-nanosecond intervals in one millisecond.

    - #### HUNDRED_NANOS_PER_MILLISECOND_BD

          static final BigDecimal HUNDRED_NANOS_PER_MILLISECOND_BD

    - #### UNIX_TO_NTFS_OFFSET

          static final long UNIX_TO_NTFS_OFFSET

      The offset of Windows time 0 to Unix epoch in 100-nanosecond intervals. Windows File Times

      A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). This is the offset of Windows time 0 to Unix epoch in 100-nanosecond intervals.

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### fromUnixTime

          public static FileTime fromUnixTime(long time)

      Converts standard Unix time (in seconds, UTC/GMT) to `FileTime`.
      Parameters:
        `time` - Unix timestamp (seconds).
      Returns:
        the corresponding FileTime.

    - #### isUnixTime

          public static boolean isUnixTime(FileTime time)

      Tests whether a FileTime can be safely represented in the standard Unix time.

      If the FileTime is null, this method returns true.

      Parameters:
        `time` - the FileTime to evaluate, can be null.
      Returns:
        true if the time exceeds the minimum or maximum Unix time, false otherwise.

    - #### isUnixTime

          public static boolean isUnixTime(long seconds)

      Tests whether a given number of seconds (since Epoch) can be safely represented in the standard Unix time.
      Parameters:
        `seconds` - the number of seconds (since Epoch) to evaluate.
      Returns:
        true if the time can be represented in the standard Unix time, false otherwise.

    - #### minusMillis

          public static FileTime minusMillis(FileTime fileTime,
                                             long millisToSubtract)

      Subtracts milliseconds from a source FileTime.
      Parameters:
        `fileTime` - The source FileTime.
        `millisToSubtract` - The milliseconds to subtract.
      Returns:
        The resulting FileTime.

    - #### minusNanos

          public static FileTime minusNanos(FileTime fileTime,
                                            long nanosToSubtract)

      Subtracts nanoseconds from a source FileTime.
      Parameters:
        `fileTime` - The source FileTime.
        `nanosToSubtract` - The nanoseconds to subtract.
      Returns:
        The resulting FileTime.

    - #### minusSeconds

          public static FileTime minusSeconds(FileTime fileTime,
                                              long secondsToSubtract)

      Subtracts seconds from a source FileTime.
      Parameters:
        `fileTime` - The source FileTime.
        `secondsToSubtract` - The seconds to subtract.
      Returns:
        The resulting FileTime.

    - #### now

          public static FileTime now()

      Obtains the current instant FileTime from the system clock.
      Returns:
        the current instant FileTime from the system clock.

    - #### ntfsTimeToDate

          static Date ntfsTimeToDate(BigDecimal ntfsTime)

    - #### ntfsTimeToDate

          public static Date ntfsTimeToDate(long ntfsTime)

      Converts an NTFS time (100 nanosecond units since 1 January 1601) to a `Date`.

      An NTFS file time is a 64-bit value for the number of 100-nanosecond intervals since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).

      Parameters:
        `ntfsTime` - the NTFS time, 100-nanosecond units since 1 January 1601.
      Returns:
        the Date input.
      See Also:
        NTFS File Times

    - #### ntfsTimeToFileTime

          public static FileTime ntfsTimeToFileTime(long ntfsTime)

      Converts an NTFS time (100-nanosecond units since 1 January 1601) to a `FileTime`.

      An NTFS file time is a 64-bit value for the number of 100-nanosecond intervals since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).

      Parameters:
        `ntfsTime` - the NTFS time, 100-nanosecond units since 1 January 1601.
      Returns:
        the FileTime input.
      See Also:
        `toNtfsTime(FileTime)`, NTFS File Times

    - #### ntfsTimeToInstant

          static java.time.Instant ntfsTimeToInstant(BigDecimal ntfsTime)

    - #### ntfsTimeToInstant

          static java.time.Instant ntfsTimeToInstant(long ntfsTime)

    - #### plusMillis

          public static FileTime plusMillis(FileTime fileTime,
                                            long millisToAdd)

      Adds milliseconds to a `FileTime`.
      Parameters:
        `fileTime` - The source FileTime.
        `millisToAdd` - The milliseconds to add.
      Returns:
        The resulting FileTime.

    - #### plusNanos

          public static FileTime plusNanos(FileTime fileTime,
                                           long nanosToSubtract)

      Adds nanoseconds to a `FileTime`.
      Parameters:
        `fileTime` - The source FileTime.
        `nanosToSubtract` - The nanoseconds to subtract.
      Returns:
        The resulting FileTime.

    - #### plusSeconds

          public static FileTime plusSeconds(FileTime fileTime,
                                             long secondsToAdd)

      Adds seconds to a `FileTime`.
      Parameters:
        `fileTime` - The source FileTime.
        `secondsToAdd` - The seconds to add.
      Returns:
        The resulting FileTime.

    - #### setLastModifiedTime

          public static void setLastModifiedTime(Path path)
                                          throws IOException

      Sets the last modified time of the given file path to now.
      Parameters:
        `path` - The file path to set.
      Throws:
        `IOException` - if an I/O error occurs.

    - #### toDate

          public static Date toDate(FileTime fileTime)

      Converts a `FileTime` to a `Date`. If the provided FileTime is `null`, the returned Date is also `null`.
      Parameters:
        `fileTime` - the file time to be converted.
      Returns:
        a `Date` which corresponds to the supplied time, or `null` if the time is `null`.
      See Also:
        `toFileTime(Date)`

    - #### toFileTime

          public static FileTime toFileTime(Date date)

      Converts a `Date` to a `FileTime`. If the provided Date is `null`, the returned FileTime is also `null`.
      Parameters:
        `date` - the date to be converted.
      Returns:
        a `FileTime` which corresponds to the supplied date, or `null` if the date is `null`.
      See Also:
        `toDate(FileTime)`

    - #### toNtfsTime

          public static long toNtfsTime(Date date)

      Converts a `Date` to NTFS time.

      An NTFS file time is a 64-bit value for the number of 100-nanosecond intervals since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).

      Parameters:
        `date` - the Date input.
      Returns:
        the NTFS time, 100-nanosecond units since 1 January 1601.

    - #### toNtfsTime

          public static long toNtfsTime(FileTime fileTime)

      Converts a `FileTime` to NTFS time (100-nanosecond units since 1 January 1601).

      An NTFS file time is a 64-bit value for the number of 100-nanosecond intervals since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).

      Parameters:
        `fileTime` - the FileTime input.
      Returns:
        the NTFS time, 100-nanosecond units since 1 January 1601.

    - #### toNtfsTime

          static long toNtfsTime(java.time.Instant instant)

    - #### toNtfsTime

          public static long toNtfsTime(long javaTime)

      Converts a Java time (milliseconds since Epoch) to NTFS time.

      An NTFS file time is a 64-bit value for the number of 100-nanosecond intervals since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).

      Parameters:
        `javaTime` - the Java time
      Returns:
        the NTFS time, 100-nanosecond units since 1 January 1601.

    - #### toUnixTime

          public static long toUnixTime(FileTime fileTime)

      Converts a `FileTime` to standard Unix time in seconds.

      The returned seconds value may lie out of bounds of Unix time. Check with `isUnixTime(long)`.

      Parameters:
        `fileTime` - the original FileTime.
      Returns:
        the Unix timestamp or 0 if the input is null.
      See Also:
        `isUnixTime(long)`