All for Joomla All for Webmasters

Java String to Date

We can convert String to Date in java using parse() method of DateFormat and SimpleDateFormat classes. To learn this concept well, you should visit DateFormat and SimpleDateFormat classes.

Java String to Date Example

Let’s see the simple code to convert String to Date in java.

  1. import java.text.SimpleDateFormat;
  2. import java.util.Date;
  3. public class StringToDateExample1 {
  4. public static void main(String[] args)throws Exception {
  5.     String sDate1=“31/12/1998”;
  6.     Date date1=new SimpleDateFormat(“dd/MM/yyyy”).parse(sDate1);
  7.     System.out.println(sDate1+“\t”+date1);
  8. }
  9. }


31/12/1998	Thu Dec 31 00:00:00 IST 1998
submit to reddit

Leave a Reply