Java examples for Date Time:Legacy Date
Convert String to Date
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String args[]){ String strDate = "21/08/2011"; try{ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date date = sdf.parse(strDate); System.out.println("Date is: " + date); }catch(ParseException e){ System.out.println("Java String could not be converted to Date: " + e); }//from w w w . j a v a 2 s . c o m } }