Class FileTimes
- java.lang.Object
-
- org.apache.commons.io.file.attribute.FileTimes
-
public final class FileTimes extends java.lang.Object
Helps useFileTime
and interoperate Date and NTFS times.- Since:
- 2.12.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.nio.file.attribute.FileTime
EPOCH
Constant for the1970-01-01T00:00:00Z
epoch
as a time stamp attribute.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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)
ConvertsFileTime
to aDate
.static java.nio.file.attribute.FileTime
toFileTime(java.util.Date date)
ConvertsDate
to aFileTime
.static long
toNtfsTime(java.nio.file.attribute.FileTime fileTime)
Converts aFileTime
to NTFS time (100-nanosecond units since 1 January 1601).static long
toNtfsTime(java.util.Date date)
Converts aDate
to NTFS time.
-
-
-
Method Detail
-
minusMillis
public static java.nio.file.attribute.FileTime minusMillis(java.nio.file.attribute.FileTime fileTime, long millisToSubtract)
Subtracts milliseconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.millisToSubtract
- The milliseconds to subtract.- Returns:
- The resulting FileTime.
-
minusNanos
public static java.nio.file.attribute.FileTime minusNanos(java.nio.file.attribute.FileTime fileTime, long nanosToSubtract)
Subtracts nanoseconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.nanosToSubtract
- The nanoseconds to subtract.- Returns:
- The resulting FileTime.
-
minusSeconds
public static java.nio.file.attribute.FileTime minusSeconds(java.nio.file.attribute.FileTime fileTime, long secondsToSubtract)
Subtracts seconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.secondsToSubtract
- The seconds to subtract.- Returns:
- The resulting FileTime.
-
now
public static java.nio.file.attribute.FileTime now()
Obtains the current instant FileTime from the system clock.- Returns:
- the current instant FileTime from the system clock.
-
ntfsTimeToDate
public static java.util.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 java.nio.file.attribute.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:
toNtfsTime(FileTime)
-
plusMillis
public static java.nio.file.attribute.FileTime plusMillis(java.nio.file.attribute.FileTime fileTime, long millisToAdd)
Adds milliseconds to a source FileTime.- Parameters:
fileTime
- The source FileTime.millisToAdd
- The milliseconds to add.- Returns:
- The resulting FileTime.
-
plusNanos
public static java.nio.file.attribute.FileTime plusNanos(java.nio.file.attribute.FileTime fileTime, long nanosToSubtract)
Adds nanoseconds from a source FileTime.- Parameters:
fileTime
- The source FileTime.nanosToSubtract
- The nanoseconds to subtract.- Returns:
- The resulting FileTime.
-
plusSeconds
public static java.nio.file.attribute.FileTime plusSeconds(java.nio.file.attribute.FileTime fileTime, long secondsToAdd)
Adds seconds to a source FileTime.- Parameters:
fileTime
- The source FileTime.secondsToAdd
- The seconds to add.- Returns:
- The resulting FileTime.
-
setLastModifiedTime
public static void setLastModifiedTime(java.nio.file.Path path) throws java.io.IOException
Sets the last modified time of the given file path to now.- Parameters:
path
- The file path to set.- Throws:
java.io.IOException
- if an I/O error occurs.
-
toDate
public static java.util.Date toDate(java.nio.file.attribute.FileTime fileTime)
ConvertsFileTime
to aDate
. If the provided FileTime isnull
, the returned Date is alsonull
.- 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(Date)
-
toFileTime
public static java.nio.file.attribute.FileTime toFileTime(java.util.Date date)
ConvertsDate
to aFileTime
. If the provided Date isnull
, the returned FileTime is alsonull
.- Parameters:
date
- the date to be converted.- Returns:
- a
FileTime
which corresponds to the supplied date, ornull
if the date isnull
. - See Also:
toDate(FileTime)
-
toNtfsTime
public static long toNtfsTime(java.util.Date date)
Converts aDate
to NTFS time.- Parameters:
date
- the Date- Returns:
- the NTFS time
-
toNtfsTime
public static long toNtfsTime(java.nio.file.attribute.FileTime fileTime)
Converts aFileTime
to NTFS time (100-nanosecond units since 1 January 1601).- Parameters:
fileTime
- the FileTime- Returns:
- the NTFS time in 100-nanosecond units
-
-