Android Question Making 2:0 look like 02:00

rleiman

Well-Known Member
Licensed User
Longtime User
Hi everyone,

I'm using the material date and time picker to select a time of 2am and it gives 2:0. I would like to format the picked time as 02:00.

Here's the coding I'm using. Can you show me what additional coding is needed to format the number?

Thanks.

B4X:
Sub TimePicked_onTimeSet(hour As Int,minute As Int, second As Int)
   
    LabelSilentPeriod1Start.Text = hour & ":" & minute
End Sub
 

Johan Schoeman

Expert
Licensed User
Longtime User
B4X:
Sub TimePicked_onTimeSet(hour As Int,minute As Int, second As Int)
    Dim hr As String = ""
    If hour < 10 then
        hr = "0" & hour
    Else
        hr = hour
    End If
    LabelSilentPeriod1Start.Text = hr & ":" & minute
End Sub


See possible solution for hour above. Same can be done for minute.
 
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Thanks for all the replies.

Both worked but I'm going with the one liner from Erel.

Erel, can you point me to a link to the language guide that describes all of the information in:

B4X:
$"$2.0{hour}

I'm going to assume $2.0 means to convert it to 2 places but I'm not sure about the rest of the syntax.

Thanks.
 
Upvote 0
Top