jdk/src/share/classes/java/sql/Date.java
changeset 15658 55b829ca2334
parent 14342 8435a30053c1
child 23010 6dadb192ad81
equal deleted inserted replaced
15657:c588664d547e 15658:55b829ca2334
    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.
   111         final int MAX_MONTH = 12;
   114         final int MAX_MONTH = 12;
   112         final int MAX_DAY = 31;
   115         final int MAX_DAY = 31;
   113         int firstDash;
   116         int firstDash;
   114         int secondDash;
   117         int secondDash;
   115         Date d = null;
   118         Date d = null;
   116 
       
   117         if (s == null) {
   119         if (s == null) {
   118             throw new java.lang.IllegalArgumentException();
   120             throw new java.lang.IllegalArgumentException();
   119         }
   121         }
   120 
   122 
   121         firstDash = s.indexOf('-');
   123         firstDash = s.indexOf('-');
   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 }