Class FileTimes
java.lang.Object
org.apache.commons.io.file.attribute.FileTimes
Helps use
FileTime
and interoperate Date and NTFS times.- Since:
- 2.12.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FileTime
Constant for the1970-01-01T00:00:00Z
epoch
as a time stamp attribute.(package private) static final long
The amount of 100-nanosecond intervals in one millisecond.private static final long
The amount of 100-nanosecond intervals in one second.(package private) static final long
The offset of Windows time 0 to Unix epoch in 100-nanosecond intervals. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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
static FileTime
toFileTime
(Date date) static long
toNtfsTime
(FileTime fileTime) Converts aFileTime
to NTFS time (100-nanosecond units since 1 January 1601).static long
toNtfsTime
(Date date) Converts aDate
to NTFS time.
-
Field Details
-
EPOCH
Constant for the1970-01-01T00:00:00Z
epoch
as a time stamp attribute.- See Also:
-
WINDOWS_EPOCH_OFFSET
static final long WINDOWS_EPOCH_OFFSETThe offset of Windows time 0 to Unix epoch in 100-nanosecond intervals. Windows File TimesA 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.
- See Also:
-
HUNDRED_NANOS_PER_SECOND
private static final long HUNDRED_NANOS_PER_SECONDThe amount of 100-nanosecond intervals in one second. -
HUNDRED_NANOS_PER_MILLISECOND
static final long HUNDRED_NANOS_PER_MILLISECONDThe amount of 100-nanosecond intervals in one millisecond.
-
-
Constructor Details
-
FileTimes
private FileTimes()
-
-
Method Details
-
minusMillis
Subtracts milliseconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.millisToSubtract
- The milliseconds to subtract.- Returns:
- The resulting FileTime.
-
minusNanos
Subtracts nanoseconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.nanosToSubtract
- The nanoseconds to subtract.- Returns:
- The resulting FileTime.
-
minusSeconds
Subtracts seconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.secondsToSubtract
- The seconds to subtract.- Returns:
- The resulting FileTime.
-
now
Obtains the current instant FileTime from the system clock.- Returns:
- the current instant FileTime from the system clock.
-
ntfsTimeToDate
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
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:
-
plusMillis
Adds milliseconds to a source FileTime.- Parameters:
fileTime
- The source FileTime.millisToAdd
- The milliseconds to add.- Returns:
- The resulting FileTime.
-
plusNanos
Adds nanoseconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.nanosToSubtract
- The nanoseconds to subtract.- Returns:
- The resulting FileTime.
-
plusSeconds
Adds seconds to a source FileTime.- Parameters:
fileTime
- The source FileTime.secondsToAdd
- The seconds to add.- Returns:
- The resulting FileTime.
-
setLastModifiedTime
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
- Parameters:
fileTime
- the file time to be converted.- Returns:
- a
Date
which corresponds to the supplied time, ornull
if the time isnull
. - See Also:
-
toFileTime
- Parameters:
date
- the date to be converted.- Returns:
- a
FileTime
which corresponds to the supplied date, ornull
if the date isnull
. - See Also:
-
toNtfsTime
Converts aDate
to NTFS time.- Parameters:
date
- the Date- Returns:
- the NTFS time
-
toNtfsTime
Converts aFileTime
to NTFS time (100-nanosecond units since 1 January 1601).- Parameters:
fileTime
- the FileTime- Returns:
- the NTFS time in 100-nanosecond units
-