Android Question Convert DatePeriod to string

trueboss323

Active Member
Licensed User
Longtime User
Using
B4X:
Dim span as Period
I want to get the time difference between 2 times.
I tried using on a button click
B4X:
Dim span2 As String
span = DateUtils.PeriodBetween(StartTime, endTime)
span2 = span
Msgbox(span2,"")
and then the message box shows:
java.lang.NumberFormatException: Invalid double: "[Days=0, Hours=0, IsInitialized=true, Minutes=0, Months=0, Seconds=14, Years=0]"

How can I change it so it appears as 00:00:14 ?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
span2 = numberformat(span.Hours,2,0)&":"&numberformat(span.Minutes,2,0)&":"&numberformat(span.Seconds,2,0)
 
Upvote 0

trueboss323

Active Member
Licensed User
Longtime User
Thanks Erel. One more question.
Is it possible to check if the time span is greater than another time span? I already used
B4X:
StateManager.SetSetting("Prevtime",PeriodToString(span))

'Check if span is greater
If PeriodToString(span) > StateManager.GetSetting("Prevtime") Then
Msgbox("You have beat your record","")
End If
 
Upvote 0
Top