71 /**
72 * The upper bound of the 32-bit unix time, the "year 2038 problem".
73 */
74 public static final long UPPER_UNIXTIME_BOUND = 0x7fffffff;
75
76 /**
77 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
78 */
79 public static final FileTime unixTimeToFileTime(long utime) {
80 return FileTime.from(utime, TimeUnit.SECONDS);
81 }
82
83 /**
84 * Converts FileTime to "standard Unix time".
85 */
86 public static final long fileTimeToUnixTime(FileTime ftime) {
87 return ftime.to(TimeUnit.SECONDS);
88 }
89
90 /**
91 /*
92 * Converts DOS time to Java time (number of milliseconds since epoch).
93 */
94 public static long dosToJavaTime(long dtime) {
95 int year = (int) (((dtime >> 25) & 0x7f) + 1980);
96 int month = (int) ((dtime >> 21) & 0x0f);
97 int day = (int) ((dtime >> 16) & 0x1f);
98 int hour = (int) ((dtime >> 11) & 0x1f);
99 int minute = (int) ((dtime >> 5) & 0x3f);
100 int second = (int) ((dtime << 1) & 0x3e);
101
102 if (month > 0 && month < 13 && day > 0 && hour < 24 && minute < 60 && second < 60) {
103 try {
104 LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
105 return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
106 ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
107 } catch (DateTimeException dte) {
108 // ignore
109 }
110 }
111 return overflowDosToJavaTime(year, month, day, hour, minute, second);
|
71 /**
72 * The upper bound of the 32-bit unix time, the "year 2038 problem".
73 */
74 public static final long UPPER_UNIXTIME_BOUND = 0x7fffffff;
75
76 /**
77 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
78 */
79 public static final FileTime unixTimeToFileTime(long utime) {
80 return FileTime.from(utime, TimeUnit.SECONDS);
81 }
82
83 /**
84 * Converts FileTime to "standard Unix time".
85 */
86 public static final long fileTimeToUnixTime(FileTime ftime) {
87 return ftime.to(TimeUnit.SECONDS);
88 }
89
90 /**
91 * Converts DOS time to Java time (number of milliseconds since epoch).
92 */
93 public static long dosToJavaTime(long dtime) {
94 int year = (int) (((dtime >> 25) & 0x7f) + 1980);
95 int month = (int) ((dtime >> 21) & 0x0f);
96 int day = (int) ((dtime >> 16) & 0x1f);
97 int hour = (int) ((dtime >> 11) & 0x1f);
98 int minute = (int) ((dtime >> 5) & 0x3f);
99 int second = (int) ((dtime << 1) & 0x3e);
100
101 if (month > 0 && month < 13 && day > 0 && hour < 24 && minute < 60 && second < 60) {
102 try {
103 LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second);
104 return TimeUnit.MILLISECONDS.convert(ldt.toEpochSecond(
105 ZoneId.systemDefault().getRules().getOffset(ldt)), TimeUnit.SECONDS);
106 } catch (DateTimeException dte) {
107 // ignore
108 }
109 }
110 return overflowDosToJavaTime(year, month, day, hour, minute, second);
|