Sunday, December 14, 2008

Convert a String to Date

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


/**
*
* @author www.javadb.com
*/
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

Post a Comment

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP