Class FileTimes
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.
- Since:
- 2.12.0
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic FileTime
fromUnixTime
(long time) Converts standard Unix time (in seconds, UTC/GMT) toFileTime
.static boolean
isUnixTime
(long seconds) Tests whether a given number of seconds (since Epoch) can be safely represented in the standard Unix time.static boolean
isUnixTime
(FileTime time) Tests whether a FileTime 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.static Date
ntfsTimeToDate
(long ntfsTime) Converts an NTFS time (100 nanosecond units since 1 January 1601) to aDate
.static FileTime
ntfsTimeToFileTime
(long ntfsTime) Converts an NTFS time (100-nanosecond units since 1 January 1601) to aFileTime
.static FileTime
plusMillis
(FileTime fileTime, long millisToAdd) Adds milliseconds to aFileTime
.static FileTime
Adds nanoseconds to aFileTime
.static FileTime
plusSeconds
(FileTime fileTime, long secondsToAdd) Adds seconds to aFileTime
.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
(long javaTime) Converts a Java time (milliseconds since Epoch) to NTFS time.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.static long
toUnixTime
(FileTime fileTime) Converts aFileTime
to standard Unix time in seconds.
-
Field Details
-
EPOCH
Constant for the1970-01-01T00:00:00Z
epoch
as 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 an NTFS time (100 nanosecond units since 1 January 1601) to aDate
.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).
- Parameters:
ntfsTime
- the NTFS time, 100-nanosecond units since 1 January 1601.- Returns:
- the Date input.
- See Also:
-
ntfsTimeToFileTime
Converts an NTFS time (100-nanosecond units since 1 January 1601) to aFileTime
.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).
- Parameters:
ntfsTime
- the NTFS time, 100-nanosecond units since 1 January 1601.- Returns:
- the FileTime input.
- See Also:
-
plusMillis
Adds milliseconds to aFileTime
.- Parameters:
fileTime
- The source FileTime.millisToAdd
- The milliseconds to add.- Returns:
- The resulting FileTime.
-
plusNanos
Adds nanoseconds to aFileTime
.- Parameters:
fileTime
- The source FileTime.nanosToSubtract
- The nanoseconds to subtract.- Returns:
- The resulting FileTime.
-
plusSeconds
Adds seconds to aFileTime
.- 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.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).
- Parameters:
date
- the Date input.- Returns:
- the NTFS time, 100-nanosecond units since 1 January 1601.
-
toNtfsTime
Converts aFileTime
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).
- Parameters:
fileTime
- the FileTime input.- Returns:
- the NTFS time, 100-nanosecond units since 1 January 1601.
-
toNtfsTime
Converts a Java time (milliseconds since Epoch) 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).
- Parameters:
javaTime
- the Java time- Returns:
- the NTFS time, 100-nanosecond units since 1 January 1601.
- Since:
- 2.16.0
-
toUnixTime
Converts aFileTime
to 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:
-