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
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic FileTimefromUnixTime(long time) Converts standard UNIX time (in seconds, UTC/GMT) toFileTime.static booleanisUnixTime(long seconds) Tests whether a given number of seconds (since Epoch) can be safely represented in the standard UNIX time.static booleanisUnixTime(FileTime time) Tests whether a FileTime can be safely represented in the standard UNIX time.static FileTimeminusMillis(FileTime fileTime, long millisToSubtract) Subtracts milliseconds from a source FileTime.static FileTimeminusNanos(FileTime fileTime, long nanosToSubtract) Subtracts nanoseconds from a source FileTime.static FileTimeminusSeconds(FileTime fileTime, long secondsToSubtract) Subtracts seconds from a source FileTime.static FileTimenow()Obtains the current instant FileTime from the system clock.static DatentfsTimeToDate(long ntfsTime) Converts NTFS time (100 nanosecond units since 1 January 1601) to Java time.static FileTimentfsTimeToFileTime(long ntfsTime) Converts NTFS time (100-nanosecond units since 1 January 1601) to a FileTime.static FileTimeplusMillis(FileTime fileTime, long millisToAdd) Adds milliseconds to a source FileTime.static FileTimeAdds nanoseconds from a source FileTime.static FileTimeplusSeconds(FileTime fileTime, long secondsToAdd) Adds seconds to a source FileTime.static voidsetLastModifiedTime(Path path) Sets the last modified time of the given file path to now.static Datestatic FileTimetoFileTime(Date date) static longtoNtfsTime(long javaTime) Converts Java time (milliseconds since Epoch) to NTFS time.static longtoNtfsTime(FileTime fileTime) Converts aFileTimeto NTFS time (100-nanosecond units since 1 January 1601).static longtoNtfsTime(Date date) Converts aDateto NTFS time.static longtoUnixTime(FileTime fileTime) ConvertsFileTimeto standard UNIX time in seconds.
-
Field Details
-
EPOCH
Constant for the1970-01-01T00:00:00Zepochas a time stamp attribute.- See Also:
-
-
Method Details
-
fromUnixTime
Converts standard UNIX time (in seconds, UTC/GMT) toFileTime.- Parameters:
time- UNIX timestamp (seconds).- Returns:
- the corresponding FileTime.
- Since:
- 2.16.0
-
isUnixTime
Tests whether a FileTime can be safely represented in the standard UNIX time.If the FileTime is null, this method returns true.
- Parameters:
time- the FileTime to evaluate, can be null.- Returns:
- true if the time exceeds the minimum or maximum UNIX time, false otherwise.
- Since:
- 2.16.0
-
isUnixTime
Tests whether a given number of seconds (since Epoch) can be safely represented in the standard UNIX time.- Parameters:
seconds- the number of seconds (since Epoch) to evaluate.- Returns:
- true if the time can be represented in the standard UNIX time, false otherwise.
- Since:
- 2.16.0
-
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
Datewhich corresponds to the supplied time, ornullif the time isnull. - See Also:
-
toFileTime
- Parameters:
date- the date to be converted.- Returns:
- a
FileTimewhich corresponds to the supplied date, ornullif the date isnull. - See Also:
-
toNtfsTime
Converts aDateto NTFS time.- Parameters:
date- the Date- Returns:
- the NTFS time
-
toNtfsTime
Converts aFileTimeto NTFS time (100-nanosecond units since 1 January 1601).- Parameters:
fileTime- the FileTime- Returns:
- the NTFS time in 100-nanosecond units
-
toNtfsTime
Converts Java time (milliseconds since Epoch) to NTFS time.- Parameters:
javaTime- the Java time- Returns:
- the NTFS time
- Since:
- 2.16.0
-
toUnixTime
ConvertsFileTimeto standard UNIX time in seconds.The returned seconds value may lie out of bounds of UNIX time. Check with
isUnixTime(long).- Parameters:
fileTime- the original FileTime.- Returns:
- the UNIX timestamp or 0 if the input is null.
- Since:
- 2.16.0
- See Also:
-