23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package java.sql; |
26 package java.sql; |
27 |
27 |
|
28 import java.time.Instant; |
|
29 import java.time.LocalDate; |
|
30 |
28 /** |
31 /** |
29 * <P>A thin wrapper around a millisecond value that allows |
32 * <P>A thin wrapper around a millisecond value that allows |
30 * JDBC to identify this as an SQL <code>DATE</code> value. A |
33 * JDBC to identify this as an SQL <code>DATE</code> value. A |
31 * milliseconds value represents the number of milliseconds that |
34 * milliseconds value represents the number of milliseconds that |
32 * have passed since January 1, 1970 00:00:00.000 GMT. |
35 * have passed since January 1, 1970 00:00:00.000 GMT. |
253 /** |
255 /** |
254 * Private serial version unique ID to ensure serialization |
256 * Private serial version unique ID to ensure serialization |
255 * compatibility. |
257 * compatibility. |
256 */ |
258 */ |
257 static final long serialVersionUID = 1511598038487230103L; |
259 static final long serialVersionUID = 1511598038487230103L; |
|
260 |
|
261 /** |
|
262 * Obtains an instance of {@code Date} from a {@link LocalDate} object |
|
263 * with the same year, month and day of month value as the given |
|
264 * {@code LocalDate}. |
|
265 * <p> |
|
266 * The provided {@code LocalDate} is interpreted as the local date |
|
267 * in the local time zone. |
|
268 * |
|
269 * @param date a {@code LocalDate} to convert |
|
270 * @return a {@code Date} object |
|
271 * @exception NullPointerException if {@code date} is null |
|
272 * @since 1.8 |
|
273 */ |
|
274 @SuppressWarnings("deprecation") |
|
275 public static Date valueOf(LocalDate date) { |
|
276 return new Date(date.getYear() - 1900, date.getMonthValue() -1, |
|
277 date.getDayOfMonth()); |
|
278 } |
|
279 |
|
280 /** |
|
281 * Converts this {@code Date} object to a {@code LocalDate} |
|
282 * <p> |
|
283 * The conversion creates a {@code LocalDate} that represents the same |
|
284 * date value as this {@code Date} in local time zone |
|
285 * |
|
286 * @return a {@code LocalDate} object representing the same date value |
|
287 * |
|
288 * @since 1.8 |
|
289 */ |
|
290 @SuppressWarnings("deprecation") |
|
291 public LocalDate toLocalDate() { |
|
292 return LocalDate.of(getYear() + 1900, getMonth() + 1, getDate()); |
|
293 } |
|
294 |
|
295 /** |
|
296 * This method always throws an UnsupportedOperationException and should |
|
297 * not be used because SQL {@code Date} values do not have a time |
|
298 * component. |
|
299 * |
|
300 * @exception java.lang.UnsupportedOperationException if this method is invoked |
|
301 */ |
|
302 @Override |
|
303 public Instant toInstant() { |
|
304 throw new java.lang.UnsupportedOperationException(); |
|
305 } |
258 } |
306 } |