Use SimpleDateFormat .
Example:
Suppose you show the current time:
Date date = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("HH:MM"); String output = sf.format(date).toString(); idtime.setText(output);
Another easy way to make a null padding, you can use String.format :
String output = String.format("%02d:%02d", mHour, mMinute); idtime.setText(output);
source share