Program to demonstrate conversion of String object to Date object in Java
Output of the program :
package com.hubberspot.examples; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class StringToDateConversion { public static void main(String[] args) { String dateFormatInString = "dd/MM/yyyy"; DateFormat df = new SimpleDateFormat(dateFormatInString); try { Date date = df.parse("20/08/2012"); System.out.println("Converted String to Date: " + df.format(date)); } catch(ParseException pe) { pe.printStackTrace(System.out); } } }
Output of the program :