Pin It

How to convert String object to a Date object in Java program ?.

Program to demonstrate conversion of String object to Date object in Java

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 :




Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot