public final class FileTimes
extends java.lang.Object
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.
| Modifier and Type | Field and Description |
|---|---|
static java.nio.file.attribute.FileTime |
EPOCH
Constant for the
1970-01-01T00:00:00Z epoch as a time stamp attribute. |
| Modifier and Type | Method and Description |
|---|---|
static java.nio.file.attribute.FileTime |
fromUnixTime(long time)
Converts standard Unix time (in seconds, UTC/GMT) to
FileTime. |
static boolean |
isUnixTime(java.nio.file.attribute.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 java.nio.file.attribute.FileTime |
minusMillis(java.nio.file.attribute.FileTime fileTime,
long millisToSubtract)
Subtracts milliseconds from a source FileTime.
|
static java.nio.file.attribute.FileTime |
minusNanos(java.nio.file.attribute.FileTime fileTime,
long nanosToSubtract)
Subtracts nanoseconds from a source FileTime.
|
static java.nio.file.attribute.FileTime |
minusSeconds(java.nio.file.attribute.FileTime fileTime,
long secondsToSubtract)
Subtracts seconds from a source FileTime.
|
static java.nio.file.attribute.FileTime |
now()
Obtains the current instant FileTime from the system clock.
|
static java.util.Date |
ntfsTimeToDate(long ntfsTime)
Converts an NTFS time (100 nanosecond units since 1 January 1601) to a
Date. |
static java.nio.file.attribute.FileTime |
ntfsTimeToFileTime(long ntfsTime)
Converts an NTFS time (100-nanosecond units since 1 January 1601) to a
FileTime. |
static java.nio.file.attribute.FileTime |
plusMillis(java.nio.file.attribute.FileTime fileTime,
long millisToAdd)
Adds milliseconds to a
FileTime. |
static java.nio.file.attribute.FileTime |
plusNanos(java.nio.file.attribute.FileTime fileTime,
long nanosToSubtract)
Adds nanoseconds to a
FileTime. |
static java.nio.file.attribute.FileTime |
plusSeconds(java.nio.file.attribute.FileTime fileTime,
long secondsToAdd)
Adds seconds to a
FileTime. |
static void |
setLastModifiedTime(java.nio.file.Path path)
Sets the last modified time of the given file path to now.
|
static java.util.Date |
toDate(java.nio.file.attribute.FileTime fileTime)
Converts a
FileTime to a Date. |
static java.nio.file.attribute.FileTime |
toFileTime(java.util.Date date)
Converts a
Date to a FileTime. |
static long |
toNtfsTime(java.util.Date date)
Converts a
Date to NTFS time. |
static long |
toNtfsTime(java.nio.file.attribute.FileTime fileTime)
Converts a
FileTime to NTFS time (100-nanosecond units since 1 January 1601). |
static long |
toNtfsTime(long javaTime)
Converts a Java time (milliseconds since Epoch) to NTFS time.
|
static long |
toUnixTime(java.nio.file.attribute.FileTime fileTime)
Converts a
FileTime to standard Unix time in seconds. |
public static final java.nio.file.attribute.FileTime EPOCH
1970-01-01T00:00:00Z epoch as a time stamp attribute.Instant.EPOCHpublic static java.nio.file.attribute.FileTime fromUnixTime(long time)
FileTime.time - Unix timestamp (seconds).public static boolean isUnixTime(java.nio.file.attribute.FileTime time)
If the FileTime is null, this method returns true.
time - the FileTime to evaluate, can be null.public static boolean isUnixTime(long seconds)
seconds - the number of seconds (since Epoch) to evaluate.public static java.nio.file.attribute.FileTime minusMillis(java.nio.file.attribute.FileTime fileTime,
long millisToSubtract)
fileTime - The source FileTime.millisToSubtract - The milliseconds to subtract.public static java.nio.file.attribute.FileTime minusNanos(java.nio.file.attribute.FileTime fileTime,
long nanosToSubtract)
fileTime - The source FileTime.nanosToSubtract - The nanoseconds to subtract.public static java.nio.file.attribute.FileTime minusSeconds(java.nio.file.attribute.FileTime fileTime,
long secondsToSubtract)
fileTime - The source FileTime.secondsToSubtract - The seconds to subtract.public static java.nio.file.attribute.FileTime now()
public static java.util.Date ntfsTimeToDate(long ntfsTime)
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).
ntfsTime - the NTFS time, 100-nanosecond units since 1 January 1601.public static java.nio.file.attribute.FileTime ntfsTimeToFileTime(long ntfsTime)
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).
ntfsTime - the NTFS time, 100-nanosecond units since 1 January 1601.toNtfsTime(FileTime),
NTFS File Timespublic static java.nio.file.attribute.FileTime plusMillis(java.nio.file.attribute.FileTime fileTime,
long millisToAdd)
FileTime.fileTime - The source FileTime.millisToAdd - The milliseconds to add.public static java.nio.file.attribute.FileTime plusNanos(java.nio.file.attribute.FileTime fileTime,
long nanosToSubtract)
FileTime.fileTime - The source FileTime.nanosToSubtract - The nanoseconds to subtract.public static java.nio.file.attribute.FileTime plusSeconds(java.nio.file.attribute.FileTime fileTime,
long secondsToAdd)
FileTime.fileTime - The source FileTime.secondsToAdd - The seconds to add.public static void setLastModifiedTime(java.nio.file.Path path)
throws java.io.IOException
path - The file path to set.java.io.IOException - if an I/O error occurs.public static java.util.Date toDate(java.nio.file.attribute.FileTime fileTime)
FileTime to a Date. If the provided FileTime is null, the returned Date is also null.fileTime - the file time to be converted.Date which corresponds to the supplied time, or null if the time is null.toFileTime(Date)public static java.nio.file.attribute.FileTime toFileTime(java.util.Date date)
Date to a FileTime. If the provided Date is null, the returned FileTime is also null.date - the date to be converted.FileTime which corresponds to the supplied date, or null if the date is null.toDate(FileTime)public static long toNtfsTime(java.util.Date date)
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).
date - the Date input.public static long toNtfsTime(java.nio.file.attribute.FileTime fileTime)
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).
fileTime - the FileTime input.public static long toNtfsTime(long javaTime)
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).
javaTime - the Java timepublic static long toUnixTime(java.nio.file.attribute.FileTime fileTime)
FileTime to standard Unix time in seconds.
The returned seconds value may lie out of bounds of Unix time. Check with isUnixTime(long).
fileTime - the original FileTime.isUnixTime(long)Copyright © 2010 - 2025 Adobe. All Rights Reserved