Possible Duplicate:
Conversion of Date
I get the date from dialog as: 5-1-2012 - as a String.
I need to convert it to 05-01-2012, string as well. What is the simpliest way to do it?
Possible Duplicate:
Conversion of Date
I get the date from dialog as: 5-1-2012 - as a String.
I need to convert it to 05-01-2012, string as well. What is the simpliest way to do it?
Do you mean?
String date = "5-1-2012";
if (date.charAt(1) == '-') date = "0" + date;
if (date.charAt(4) == '-') date = date.substring(0,3) + "0" + date.substring(3);
// date is 05-01-2012
SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy");
String format = s.format(new Date());
If you plan to use it as a Date object later, I would use the SimpleDateFormat parse() function...
you may test your string to determine whether to use a d-M-yyyy or dd-MM-yyyy pattern for the parser