org.apache.commons.compress.utils

## Class TimeUtils

- java.lang.Object
- - org.apache.commons.compress.utils.TimeUtils

-     public final class TimeUtils
      extends Object

  Utility class for handling time-related types and conversions.

  Understanding Unix vs NTFS timestamps:

  - A Unix timestamp is a primitive long starting at the Unix Epoch on January 1st, 1970 at Coordinated Universal Time (UTC)
  - An NTFS timestamp is 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).
  Since:
    1.23

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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 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 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).
    `static long` | `toNtfsTime(long javaTime)` Converts Java time (milliseconds since Epoch) to NTFS time.
    `static long` | `toUnixTime(FileTime fileTime)` Converts `FileTime` to standard UNIX time.
    `static FileTime` | `truncateToHundredNanos(FileTime fileTime)` Truncates a FileTime to 100-nanosecond precision.
    `static FileTime` | `unixTimeToFileTime(long time)` Converts standard UNIX time (in seconds, UTC/GMT) to `FileTime`.

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

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

- - ### Method Detail

    - #### isUnixTime

          public static boolean isUnixTime(FileTime time)

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

      TODO ? If the FileTime is null, this method always 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

    - #### 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:
        `WINDOWS_EPOCH_OFFSET`, `toNtfsTime(FileTime)`

    - #### 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
      See Also:
        `WINDOWS_EPOCH_OFFSET`, `ntfsTimeToFileTime(long)`

    - #### toNtfsTime

          public static long toNtfsTime(long javaTime)

      Converts Java time (milliseconds since Epoch) to NTFS time.
      Parameters:
        `javaTime` - the Java time
      Returns:
        the NTFS time

    - #### toUnixTime

          public static long toUnixTime(FileTime fileTime)

      Converts `FileTime` to standard UNIX time.
      Parameters:
        `fileTime` - the original FileTime
      Returns:
        the UNIX timestamp

    - #### truncateToHundredNanos

          public static FileTime truncateToHundredNanos(FileTime fileTime)

      Truncates a FileTime to 100-nanosecond precision.
      Parameters:
        `fileTime` - the FileTime to be truncated
      Returns:
        the truncated FileTime

    - #### unixTimeToFileTime

          public static FileTime unixTimeToFileTime(long time)

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

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