public final class FileTimes extends 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 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.
|
| 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)
|
static FileTime |
toFileTime(Date date)
|
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. |
public static final FileTime EPOCH
1970-01-01T00:00:00Z epoch as a time stamp attribute.Instant.EPOCHstatic final long HUNDRED_NANOS_PER_MILLISECOND
static final BigDecimal HUNDRED_NANOS_PER_MILLISECOND_BD
static final long UNIX_TO_NTFS_OFFSET
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.
public static FileTime fromUnixTime(long time)
FileTime.time - Unix timestamp (seconds).public static boolean isUnixTime(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 FileTime minusMillis(FileTime fileTime, long millisToSubtract)
fileTime - The source FileTime.millisToSubtract - The milliseconds to subtract.public static FileTime minusNanos(FileTime fileTime, long nanosToSubtract)
fileTime - The source FileTime.nanosToSubtract - The nanoseconds to subtract.public static FileTime minusSeconds(FileTime fileTime, long secondsToSubtract)
fileTime - The source FileTime.secondsToSubtract - The seconds to subtract.public static FileTime now()
static Date ntfsTimeToDate(BigDecimal ntfsTime)
public static 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 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 Timesstatic java.time.Instant ntfsTimeToInstant(BigDecimal ntfsTime)
static java.time.Instant ntfsTimeToInstant(long ntfsTime)
public static FileTime plusMillis(FileTime fileTime, long millisToAdd)
FileTime.fileTime - The source FileTime.millisToAdd - The milliseconds to add.public static FileTime plusNanos(FileTime fileTime, long nanosToSubtract)
FileTime.fileTime - The source FileTime.nanosToSubtract - The nanoseconds to subtract.public static FileTime plusSeconds(FileTime fileTime, long secondsToAdd)
FileTime.fileTime - The source FileTime.secondsToAdd - The seconds to add.public static void setLastModifiedTime(Path path) throws IOException
path - The file path to set.IOException - if an I/O error occurs.public static Date toDate(FileTime fileTime)
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 FileTime toFileTime(Date date)
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(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(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.static long toNtfsTime(java.time.Instant instant)
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(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)