• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Textclock not displaying tens value

I am adding a clock to my app but whenever the tens minute is at 0 (eg. 11:05) it will not display the tens minute (eg. 11:5). How do I fix this?
 
I'm not a developer so I probably won't be able to help, but it might help the other developers help you if you shared some of the code you're using. You can wrap it in [code]...[/code] tags to help make it easier to read.
 
Do you mean that your clock string will show '11:5' rather than '11:05' when the time is 11:05?

If so, the codes as below are for your reference.

Code:
import java.util.Calendar

Calendar rightNow = Calendar.getInstance();

int nHour = rightNow.get(Calendar.HOUR_OF_DAY);
int nMinutes = rightNow.get(Calendar.MINUTE);
int nSeconds = rightNow.get(Calendar.SECOND);

String strClock = String.format("%02d:%02d:%02d", nHour, nMinute, nSecond);
 
Do you mean that your clock string will show '11:5' rather than '11:05' when the time is 11:05?

If so, the codes as below are for your reference.

Code:
import java.util.Calendar

Calendar rightNow = Calendar.getInstance();

int nHour = rightNow.get(Calendar.HOUR_OF_DAY);
int nMinutes = rightNow.get(Calendar.MINUTE);
int nSeconds = rightNow.get(Calendar.SECOND);

String strClock = String.format("%02d:%02d:%02d", nHour, nMinute, nSecond);
I tried using that code and it worked, however, it only shows the time the app was started and doesn't change. is there a way of making it always show the correct time?
 
Back
Top Bottom