Calendar.MINUTE giving minutes without leading zero

Viewed 36105

Hi all I am using below code to get android phone time, but it is giving me minutes without zero if the minutes are in between 1 to 9.

for example:right now I have time on my device 12:09 but its giving me as 12:9

Calendar c = Calendar.getInstance();
int hrs = c.get(Calendar.HOUR);
int mnts = c.get(Calendar.MINUTE);
String curTime = "" + hrs + ":" + mnts;
return curTime;

after above code I also try below code its giving same thing as above, minutes without zero before number it the minutes in between 1 to 9 . .

final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
Date date = cal.getTime();
int mHour = date.getHours();
int mMinute = date.getMinutes();
5 Answers
Related