jdk/src/share/classes/java/sql/Time.java
changeset 15658 55b829ca2334
parent 14342 8435a30053c1
child 23010 6dadb192ad81
--- a/jdk/src/share/classes/java/sql/Time.java	Tue Feb 12 16:02:14 2013 +0400
+++ b/jdk/src/share/classes/java/sql/Time.java	Tue Feb 12 09:25:43 2013 -0800
@@ -25,6 +25,9 @@
 
 package java.sql;
 
+import java.time.Instant;
+import java.time.LocalTime;
+
 /**
  * <P>A thin wrapper around the <code>java.util.Date</code> class that allows the JDBC
  * API to identify this as an SQL <code>TIME</code> value. The <code>Time</code>
@@ -246,4 +249,45 @@
     * compatibility.
     */
     static final long serialVersionUID = 8397324403548013681L;
+
+    /**
+     * Obtains an instance of {@code Time} from a {@link LocalTime} object
+     * with the same hour, minute and second time value as the given
+     * {@code LocalTime}.
+     *
+     * @param time a {@code LocalTime} to convert
+     * @return a {@code Time} object
+     * @exception NullPointerException if {@code time} is null
+     * @since 1.8
+     */
+    @SuppressWarnings("deprecation")
+    public static Time valueOf(LocalTime time) {
+        return new Time(time.getHour(), time.getMinute(), time.getSecond());
+    }
+
+    /**
+     * Converts this {@code Time} object to a {@code LocalTime}.
+     * <p>
+     * The conversion creates a {@code LocalTime} that represents the same
+     * hour, minute, and second time value as this {@code Time}.
+     *
+     * @return a {@code LocalTime} object representing the same time value
+     * @since 1.8
+     */
+    @SuppressWarnings("deprecation")
+    public LocalTime toLocalTime() {
+        return LocalTime.of(getHours(), getMinutes(), getSeconds());
+    }
+
+   /**
+    * This method always throws an UnsupportedOperationException and should
+    * not be used because SQL {@code Time} values do not have a date
+    * component.
+    *
+    * @exception java.lang.UnsupportedOperationException if this method is invoked
+    */
+    @Override
+    public Instant toInstant() {
+        throw new java.lang.UnsupportedOperationException();
+    }
 }