Convert Util Date To Sql Date In Java

 Posted On  | Yashwant Chavan 

Most of the time we required to convert the java util date to java sql date.Pass the milliseconds time value to the constructor of java.sql.Date class.The java.util.Date class has the method getTime() which returns milliseconds time value. Or you can make it vice versa.

Java util date to sql date

package com.technicalkeeda.app;

public class DateExample {
    public static void main(String[] args) {
        java.util.Date util = new java.util.Date();
        java.sql.Date sql = new java.sql.Date(util.getTime());

        System.out.println("util date:- " + util);
        System.out.println("sql date:- " + sql);

    }

}

Output

util date:- Tue Nov 29 09:04:18 IST 2016
sql date:- 2016-11-29


© technicalkeeda.com 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0545 seconds.