Hello. I'm trying to convert Calendar to dd/MM/yyyy format.
My problem was it couldn't convert to exactly what i wanted. I'm Turkish so when we write a date, we write the day first then month then year...
My code is here
public static String toFormattedDateString(Calendar input){
String year = null;
String month = null;
String day = null;
if(input.get(Calendar.MONTH)<9){
System.out.println("Calendar.MONTH--->"+input.get(Calendar.MONTH));
int monthInt = input.get(Calendar.MONTH);
monthInt++;
month = "0";
month += (new Integer(monthInt)).toString();
}
else
month = (new Integer(input.get(Calendar.MONTH)+1)).toString();
if(input.get(Calendar.DAY_OF_MONTH)<10)
day = "0"+ (new Integer(input.get(Calendar.DAY_OF_MONTH))).toString();
else
day = (new Integer(input.get(Calendar.DAY_OF_MONTH))).toString();
year = new Integer(input.get(Calendar.YEAR)).toString();
return day+"/"+month+"/"+year;
}
And it can't convert to what i want exactly. Here are some results.
01.02.2009---> It couldn't convert it correctly. Added dots and 01 is the month and 02 is the day.
17/01/2009 ---> This is the correct result. dd/MM/yyyy format
01.02.2009----> Wrong again.