I am using below method to display the time.
public static String getTimeByTimezone(String timeZone,Calendar localTime){
String time ="";
Calendar indiaTime = new GregorianCalendar(TimeZone.getTimeZone(timeZone));
indiaTime.setTimeInMillis(localTime.getTimeInMillis());
int hour = indiaTime.get(Calendar.HOUR);
int minute = indiaTime.get(Calendar.MINUTE);
int second = indiaTime.get(Calendar.SECOND);
int year = indiaTime.get(Calendar.YEAR);
// /int am = indiaTime.get(Calendar.AM_PM);
//System.out.printf("India time: %02d:%02d:%02d %02d\n", hour, minute, second, year);
time = hour+":"+minute;
if(indiaTime.get(Calendar.AM_PM)==0)
time=time+" AM";
else
time=time+" PM";
return time;
}
So what ever result is coming, if hour is less then 10 its appearing with single digits and same with the minutes, if minute is less then 10 its appearing with one digit. Ex: For Hour - > Getting: 9:15 AM Expected: 09:15 AM For Minute -> Getting: 9:8 AM Expected: 09:08 AM Can anybody tell me how to deal with digits.