Class TimeUtils
- java.lang.Object
-
- org.apache.commons.compress.utils.TimeUtils
-
public final class TimeUtils extends java.lang.ObjectUtility class for handling time-related types and conversions.Understanding UNIX vs NTFS timestamps:
- A UNIX timestamp is a primitive long starting at the UNIX Epoch on January 1st, 1970 at Coordinated Universal Time (UTC)
- An NTFS timestamp is 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).
- Since:
- 1.23
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanisUnixTime(long seconds)Tests whether a given number of seconds (since Epoch) can be safely represented in the standard UNIX time.static booleanisUnixTime(java.nio.file.attribute.FileTime time)Tests whether a FileTime can be safely represented in the standard UNIX time.static java.util.DatentfsTimeToDate(long ntfsTime)Deprecated.static java.nio.file.attribute.FileTimentfsTimeToFileTime(long ntfsTime)Deprecated.static java.util.DatetoDate(java.nio.file.attribute.FileTime fileTime)Deprecated.static java.nio.file.attribute.FileTimetoFileTime(java.util.Date date)Deprecated.static longtoNtfsTime(long javaTime)Converts Java time (milliseconds since Epoch) to NTFS time.static longtoNtfsTime(java.nio.file.attribute.FileTime fileTime)Deprecated.static longtoNtfsTime(java.util.Date date)Deprecated.static longtoUnixTime(java.nio.file.attribute.FileTime fileTime)ConvertsFileTimeto standard UNIX time.static java.nio.file.attribute.FileTimetruncateToHundredNanos(java.nio.file.attribute.FileTime fileTime)Truncates a FileTime to 100-nanosecond precision.static java.nio.file.attribute.FileTimeunixTimeToFileTime(long time)Converts standard UNIX time (in seconds, UTC/GMT) toFileTime.
-
-
-
Method Detail
-
isUnixTime
public static boolean isUnixTime(java.nio.file.attribute.FileTime time)
Tests whether a FileTime can be safely represented in the standard UNIX time.TODO ? If the FileTime is null, this method always 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.
-
isUnixTime
public static boolean isUnixTime(long seconds)
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.
-
ntfsTimeToDate
@Deprecated public static java.util.Date ntfsTimeToDate(long ntfsTime)
Deprecated.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
@Deprecated public static java.nio.file.attribute.FileTime ntfsTimeToFileTime(long ntfsTime)
Deprecated.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:
FileTimes.toNtfsTime(FileTime)
-
toDate
@Deprecated public static java.util.Date toDate(java.nio.file.attribute.FileTime fileTime)
Deprecated.ConvertsFileTimeto aDate. If the provided FileTime isnull, the returned Date is alsonull.- Parameters:
fileTime- the file time to be converted.- Returns:
- a
Datewhich corresponds to the supplied time, ornullif the time isnull. - See Also:
FileTimes.toFileTime(Date)
-
toFileTime
@Deprecated public static java.nio.file.attribute.FileTime toFileTime(java.util.Date date)
Deprecated.ConvertsDateto aFileTime. If the provided Date isnull, the returned FileTime is alsonull.- Parameters:
date- the date to be converted.- Returns:
- a
FileTimewhich corresponds to the supplied date, ornullif the date isnull. - See Also:
FileTimes.toDate(FileTime)
-
toNtfsTime
@Deprecated public static long toNtfsTime(java.util.Date date)
Deprecated.Converts aDateto NTFS time.- Parameters:
date- the Date.- Returns:
- the NTFS time.
-
toNtfsTime
@Deprecated public static long toNtfsTime(java.nio.file.attribute.FileTime fileTime)
Deprecated.Converts aFileTimeto NTFS time (100-nanosecond units since 1 January 1601).- Parameters:
fileTime- the FileTime.- Returns:
- the NTFS time in 100-nanosecond units.
- See Also:
FileTimes.ntfsTimeToFileTime(long)
-
toNtfsTime
public static long toNtfsTime(long javaTime)
Converts Java time (milliseconds since Epoch) to NTFS time.- Parameters:
javaTime- the Java time.- Returns:
- the NTFS time.
-
toUnixTime
public static long toUnixTime(java.nio.file.attribute.FileTime fileTime)
ConvertsFileTimeto standard UNIX time.- Parameters:
fileTime- the original FileTime.- Returns:
- the UNIX timestamp.
-
truncateToHundredNanos
public static java.nio.file.attribute.FileTime truncateToHundredNanos(java.nio.file.attribute.FileTime fileTime)
Truncates a FileTime to 100-nanosecond precision.- Parameters:
fileTime- the FileTime to be truncated.- Returns:
- the truncated FileTime.
-
unixTimeToFileTime
public static java.nio.file.attribute.FileTime unixTimeToFileTime(long time)
Converts standard UNIX time (in seconds, UTC/GMT) toFileTime.- Parameters:
time- UNIX timestamp (in seconds, UTC/GMT).- Returns:
- the corresponding FileTime.
-
-