Sample Programs

Sample java program to convert String to Date

 package org.jusfortechies.example; 

 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 public class StringToDate {

   private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
	
   private static final String DATE_FORMAT = "MM/dd/yyyy";
	
   public static void main(String[] args) {
      try {
         simpleDateFormat.applyPattern(DATE_FORMAT);
         Date date = simpleDateFormat.parse("12/12/2000");
			
         System.out.println("The parsed date = " + date);
			 
      } catch (ParseException e) {
         System.err.println("Given date could not be parsed : " + e);
      }
   }

 }




blog comments powered by Disqus