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.
  Since:
    2.12.0

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

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `static Date` | `ntfsTimeToDate(long ntfsTime)` Converts NTFS time (100 nanosecond units since 1 January 1601) to Java time.
    `static FileTime` | `ntfsTimeToFileTime(long ntfsTime)` Converts NTFS time (100-nanosecond units since 1 January 1601) to a FileTime.
    `static FileTime` | `plusMillis(FileTime fileTime, long millisToAdd)` Adds milliseconds to a source FileTime.
    `static FileTime` | `plusNanos(FileTime fileTime, long nanosToSubtract)` Adds nanoseconds from a source FileTime.
    `static FileTime` | `plusSeconds(FileTime fileTime, long secondsToAdd)` Adds seconds to a source FileTime.
    `static void` | `setLastModifiedTime(Path path)` Sets the last modified time of the given file path to now.
    `static Date` | `toDate(FileTime fileTime)` Converts `FileTime` to a `Date`.
    `static FileTime` | `toFileTime(Date date)` Converts `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).

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

  - ### Method Detail

    - #### 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

          public static Date ntfsTimeToDate(long ntfsTime)

      Converts NTFS time (100 nanosecond units since 1 January 1601) to Java time.
      Parameters:
        `ntfsTime` - the NTFS time in 100 nanosecond units
      Returns:
        the Date

    - #### ntfsTimeToFileTime

          public static FileTime ntfsTimeToFileTime(long ntfsTime)

      Converts NTFS time (100-nanosecond units since 1 January 1601) to a FileTime.
      Parameters:
        `ntfsTime` - the NTFS time in 100-nanosecond units
      Returns:
        the FileTime
      See Also:
        `toNtfsTime(FileTime)`

    - #### plusMillis

          public static FileTime plusMillis(FileTime fileTime,
                                            long millisToAdd)

      Adds milliseconds to a source 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 from a source 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 source 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 `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 `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.
      Parameters:
        `date` - the Date
      Returns:
        the NTFS time

    - #### toNtfsTime

          public static long toNtfsTime(FileTime fileTime)

      Converts a `FileTime` to NTFS time (100-nanosecond units since 1 January 1601).
      Parameters:
        `fileTime` - the FileTime
      Returns:
        the NTFS time in 100-nanosecond units

Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.