I need to show date and time in this format, Date: 9th Dec, Time: 19:20
Although my following code is working fine in English, have no idea this is correct way in other languages which my application is supporting like Chinese, Thai, etc. Any idea would be appreciated? Thanks
This is my code:
private String getFormattedTime(Calendar calendar)
{
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
StringBuilder sBuilder = new StringBuilder(4);
sBuilder.append(hour);
sBuilder.append(":");
// We want to display the hour like this: 12:09,
// but by not using following code it becomes 12:9
if (minute < 10)
{
sBuilder.append("0");
}
sBuilder.append(minute);
return sBuilder.toString();
}
private String getDateSuffix( int day)
{
if (day < 1 || day > 31)
{
throw new IllegalArgumentException("Illegal day of month");
}
switch (day)
{
case 1:
case 21:
case 31:
return ("st");
case 2:
case 22:
return ("nd");
case 3:
case 23:
return ("rd");
default:
return ("th");
}
}