Convert a String to Date

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;



public class Main {
    
    public void convertStringToDate(int date, int month, int year) {
        
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
 
        String in = date + "/" + month + "/" + year;
        try {
            
            Date theDate = dateFormat.parse(in); 
            System.out.println("Date parsed = " + dateFormat.format(theDate));
            
        } catch (ParseException e) {
            e.printStackTrace();
        }
        
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main().convertStringToDate(01, 01, 2015);
    }
}
 

 

The output from the code above looks like:


Date parsed = 01/01/2015

0 comments:

                                                                

Site Meter