203 * <p> If the entry is output to a ZIP file or ZIP file formatted 204 * output stream the last modification time set by this method will 205 * be stored into the {@code date and time fields} of the zip file 206 * entry and encoded in standard {@code MS-DOS date and time format}. 207 * If the date-time set is out of the range of the standard {@code 208 * MS-DOS date and time format}, the time will also be stored into 209 * zip file entry's extended timestamp fields in {@code optional 210 * extra data} in UTC time. The {@link java.time.ZoneId#systemDefault() 211 * system default TimeZone} is used to convert the local date-time 212 * to UTC time. 213 * 214 * <p> {@code LocalDateTime} uses a precision of nanoseconds, whereas 215 * this class uses a precision of milliseconds. The conversion will 216 * truncate any excess precision information as though the amount in 217 * nanoseconds was subject to integer division by one million. 218 * 219 * @param time 220 * The last modification time of the entry in local date-time 221 * 222 * @see #getTimeLocal() 223 * @since 1.9 224 */ 225 public void setTimeLocal(LocalDateTime time) { 226 int year = time.getYear() - 1980; 227 if (year < 0) { 228 this.xdostime = DOSTIME_BEFORE_1980; 229 } else { 230 this.xdostime = (year << 25 | 231 time.getMonthValue() << 21 | 232 time.getDayOfMonth() << 16 | 233 time.getHour() << 11 | 234 time.getMinute() << 5 | 235 time.getSecond() >> 1) 236 + ((long)(((time.getSecond() & 0x1) * 1000) + 237 time.getNano() / 1000_000) << 32); 238 } 239 if (xdostime != DOSTIME_BEFORE_1980 && year <= 0x7f) { 240 this.mtime = null; 241 } else { 242 this.mtime = FileTime.from( 243 ZonedDateTime.of(time, ZoneId.systemDefault()).toInstant()); 244 } 245 } 246 247 /** 248 * Returns the last modification time of the entry in local date-time. 249 * 250 * <p> If the entry is read from a ZIP file or ZIP file formatted 251 * input stream, this is the last modification time from the zip 252 * file entry's {@code optional extra data} if the extended timestamp 253 * fields are present. Otherwise, the last modification time is read 254 * from entry's standard MS-DOS formatted {@code date and time fields}. 255 * 256 * <p> The {@link java.time.ZoneId#systemDefault() system default TimeZone} 257 * is used to convert the UTC time to local date-time. 258 * 259 * @return The last modification time of the entry in local date-time 260 * 261 * @see #setTimeLocal(LocalDateTime) 262 * @since 1.9 263 */ 264 public LocalDateTime getTimeLocal() { 265 if (mtime != null) { 266 return LocalDateTime.ofInstant(mtime.toInstant(), ZoneId.systemDefault()); 267 } 268 int ms = (int)(xdostime >> 32); 269 return LocalDateTime.of((int)(((xdostime >> 25) & 0x7f) + 1980), 270 (int)((xdostime >> 21) & 0x0f), 271 (int)((xdostime >> 16) & 0x1f), 272 (int)((xdostime >> 11) & 0x1f), 273 (int)((xdostime >> 5) & 0x3f), 274 (int)((xdostime << 1) & 0x3e) + ms / 1000, 275 (ms % 1000) * 1000_000); 276 } 277 278 279 /** 280 * Sets the last modification time of the entry. 281 * 282 * <p> When output to a ZIP file or ZIP file formatted output stream | 203 * <p> If the entry is output to a ZIP file or ZIP file formatted 204 * output stream the last modification time set by this method will 205 * be stored into the {@code date and time fields} of the zip file 206 * entry and encoded in standard {@code MS-DOS date and time format}. 207 * If the date-time set is out of the range of the standard {@code 208 * MS-DOS date and time format}, the time will also be stored into 209 * zip file entry's extended timestamp fields in {@code optional 210 * extra data} in UTC time. The {@link java.time.ZoneId#systemDefault() 211 * system default TimeZone} is used to convert the local date-time 212 * to UTC time. 213 * 214 * <p> {@code LocalDateTime} uses a precision of nanoseconds, whereas 215 * this class uses a precision of milliseconds. The conversion will 216 * truncate any excess precision information as though the amount in 217 * nanoseconds was subject to integer division by one million. 218 * 219 * @param time 220 * The last modification time of the entry in local date-time 221 * 222 * @see #getTimeLocal() 223 * @since 9 224 */ 225 public void setTimeLocal(LocalDateTime time) { 226 int year = time.getYear() - 1980; 227 if (year < 0) { 228 this.xdostime = DOSTIME_BEFORE_1980; 229 } else { 230 this.xdostime = (year << 25 | 231 time.getMonthValue() << 21 | 232 time.getDayOfMonth() << 16 | 233 time.getHour() << 11 | 234 time.getMinute() << 5 | 235 time.getSecond() >> 1) 236 + ((long)(((time.getSecond() & 0x1) * 1000) + 237 time.getNano() / 1000_000) << 32); 238 } 239 if (xdostime != DOSTIME_BEFORE_1980 && year <= 0x7f) { 240 this.mtime = null; 241 } else { 242 this.mtime = FileTime.from( 243 ZonedDateTime.of(time, ZoneId.systemDefault()).toInstant()); 244 } 245 } 246 247 /** 248 * Returns the last modification time of the entry in local date-time. 249 * 250 * <p> If the entry is read from a ZIP file or ZIP file formatted 251 * input stream, this is the last modification time from the zip 252 * file entry's {@code optional extra data} if the extended timestamp 253 * fields are present. Otherwise, the last modification time is read 254 * from entry's standard MS-DOS formatted {@code date and time fields}. 255 * 256 * <p> The {@link java.time.ZoneId#systemDefault() system default TimeZone} 257 * is used to convert the UTC time to local date-time. 258 * 259 * @return The last modification time of the entry in local date-time 260 * 261 * @see #setTimeLocal(LocalDateTime) 262 * @since 9 263 */ 264 public LocalDateTime getTimeLocal() { 265 if (mtime != null) { 266 return LocalDateTime.ofInstant(mtime.toInstant(), ZoneId.systemDefault()); 267 } 268 int ms = (int)(xdostime >> 32); 269 return LocalDateTime.of((int)(((xdostime >> 25) & 0x7f) + 1980), 270 (int)((xdostime >> 21) & 0x0f), 271 (int)((xdostime >> 16) & 0x1f), 272 (int)((xdostime >> 11) & 0x1f), 273 (int)((xdostime >> 5) & 0x3f), 274 (int)((xdostime << 1) & 0x3e) + ms / 1000, 275 (ms % 1000) * 1000_000); 276 } 277 278 279 /** 280 * Sets the last modification time of the entry. 281 * 282 * <p> When output to a ZIP file or ZIP file formatted output stream |