Java examples for Date Time:Legacy Date
Convert String to java.sql.Date
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); } }