Convert String to java.sql.Date - Java Date Time

Java examples for Date Time:Legacy Date

Description

Convert String to java.sql.Date

Demo Code


import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
 
public class Main {
       /*w  w w.  j  av  a 2 s .  co m*/
        public static void main(String args[]) throws ParseException{
                String strDate = "2011-12-31 00:00:00";
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
                java.util.Date date = sdf.parse(strDate);
                java.sql.Date sqlDate = new Date(date.getTime());
                System.out.println("String converted to java.sql.Date :" + sqlDate);
        }
}
 

Result


Related Tutorials