Formatting user input Date.
Hi
I am having problem in changing the format of a user input date. I develop code with some methods for changing format and it is working. Only problem is displaying ?for example if month or date is ?st /Jan/ 2007?then it should appear ?1/01/2007?what I am getting is ?/1/2007? I will really appreciate for any help in getting the solution also if there is any way to use API to do so.
Following is my code for the above.
/**
*
*/
package test;
/**
* @author Destiny
*
*/
public class Date_Format {
String d_f = "05-05-2007"; //String date from user
int dd = Integer.parseInt( d_f.substring(0, 2));
int MM = Integer.parseInt(d_f.substring(3, 5));
String months[] = {
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "July", "Aug",
"Sep", "Oct", "Nov", "Dec"};
int yyyy = Integer.parseInt(d_f.substring(6, 10));
public void month_first(){
System.out.println(MM+"-"+dd+"-"+yyyy); // MM-dd-yyyy
}
public void year_first(){
System.out.println(yyyy+"-"+dd+"-"+MM); // yyyy-dd-MM
}
public void month_name_first(){
System.out.println(months[MM-1]+"/"+dd+"/"+yyyy); // (Jan or whatever)MM/dd/yyyy
}
public void month_name_second(){
System.out.println(dd+"/"+months[MM-1]+"/"+yyyy);// dd/(Jan or whatever)MM/yyyy
}
public static void main (String args[]){
Date_Format dd_f = new Date_Format();
dd_f.month_first();
dd_f.year_first();
dd_f.month_name_first();
dd_f.month_name_second();
}
}
/*
* Code End
*/
Thank You.

