public final class FileTimes
extends java.lang.Object
FileTime
and interoperate Date and NTFS times.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. |
(package private) static long |
HUNDRED_NANOS_PER_MILLISECOND
The amount of 100-nanosecond intervals in one millisecond.
|
private static long |
HUNDRED_NANOS_PER_SECOND
The amount of 100-nanosecond intervals in one second.
|
(package private) static long |
WINDOWS_EPOCH_OFFSET
The offset of Windows time 0 to Unix epoch in 100-nanosecond intervals.
|
Modifier | Constructor and Description |
---|---|
private |
FileTimes() |
Modifier and Type | Method and Description |
---|---|
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 NTFS time (100 nanosecond units since 1 January 1601) to Java time.
|
static java.nio.file.attribute.FileTime |
ntfsTimeToFileTime(long ntfsTime)
Converts 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 source FileTime.
|
static java.nio.file.attribute.FileTime |
plusNanos(java.nio.file.attribute.FileTime fileTime,
long nanosToSubtract)
Adds nanoseconds from a source FileTime.
|
static java.nio.file.attribute.FileTime |
plusSeconds(java.nio.file.attribute.FileTime fileTime,
long secondsToAdd)
Adds seconds to a source 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
FileTime to a Date . |
static java.nio.file.attribute.FileTime |
toFileTime(java.util.Date date)
Converts
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). |
public static final java.nio.file.attribute.FileTime EPOCH
1970-01-01T00:00:00Z
epoch
as a time stamp attribute.Instant.EPOCH
static final long WINDOWS_EPOCH_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.
private static final long HUNDRED_NANOS_PER_SECOND
static final long HUNDRED_NANOS_PER_MILLISECOND
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)
ntfsTime
- the NTFS time in 100 nanosecond unitspublic static java.nio.file.attribute.FileTime ntfsTimeToFileTime(long ntfsTime)
ntfsTime
- the NTFS time in 100-nanosecond unitstoNtfsTime(FileTime)
public static java.nio.file.attribute.FileTime plusMillis(java.nio.file.attribute.FileTime fileTime, long millisToAdd)
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
- 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
- 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.date
- the Datepublic static long toNtfsTime(java.nio.file.attribute.FileTime fileTime)
FileTime
to NTFS time (100-nanosecond units since 1 January 1601).fileTime
- the FileTime