My application displays time left in such format hh:mm:ss, for example, 01:05:45 what stands for one hour 5 minutes and 45 seconds.
When hours or minutes are zero I would like not to display them. Currently, if 45 seconds are remaining my timer will show '00:00:45'. The expected result is just '45'.
I need some kind of Java/Kotlin/Android method to produce the following outputs:
- 1 hour 13 minutes and 10 seconds ==> 01:13:10
- 0 hours 13 minutes and 10 seconds ==> 13:10
- 3 hours 0 minutes and 16 seconds ==> 03:00:16
- 0 hour 0 minutes and 5 seconds ==> 5
Currently I use such string as a formatter:
<string name="time_default_formatter" translatable="false">%02d:%02d:%02d</string>
I tried to manually replace string "00:" with "" but it fails when it comes to a 3rd example. Also, I think standard formatting should provide something like that but I keep failing to find it.
Edit: I can do it in code. The thing is I am looking for an elegant solution.