I´m trying to display the "two numbers" of minute in my code with an Android TimePicker. But I didn´t get it yet... The time is only displayed in this format X:X. For example 9:05 will show in my app 9:5.
Can anyone help me please?
This is my code...
idtime.setText(new StringBuilder()
.append(String.valueOf(mHour)).append(":")
.append(String.valueOf(mMinute)).toString());
Use SimpleDateFormat.
Example:
Suppose you are displaying the current time:
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("HH:MM");
String output = sf.format(date).toString();
idtime.setText(output);
Another easier method to do zero-padding, you can use String.format
:
String output = String.format("%02d:%02d", mHour, mMinute);
idtime.setText(output);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With