T trueboss323 Active Member Licensed User Longtime User Feb 23, 2015 #1 Using Code: Copy Dim span as Period I want to get the time difference between 2 times. I tried using on a button click Code: Copy 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 ?
Using Code: Copy Dim span as Period I want to get the time difference between 2 times. I tried using on a button click Code: Copy 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 ?
Erel B4X founder Staff member Licensed User Longtime User Feb 23, 2015 #2 You need to convert the period to such formatted string. It will not happen automatically. Code: Copy Sub PeriodToString(p As Period) As String Return $"$2{p.Hours}:$2{p.Minutes}:$2{p.Seconds}"$ End Sub Log(PeriodToString(span)) Upvote 0
You need to convert the period to such formatted string. It will not happen automatically. Code: Copy Sub PeriodToString(p As Period) As String Return $"$2{p.Hours}:$2{p.Minutes}:$2{p.Seconds}"$ End Sub Log(PeriodToString(span))
DonManfred Expert Licensed User Longtime User Feb 23, 2015 #3 Code: Copy span2 = numberformat(span.Hours,2,0)&":"&numberformat(span.Minutes,2,0)&":"&numberformat(span.Seconds,2,0) Upvote 0
Code: Copy span2 = numberformat(span.Hours,2,0)&":"&numberformat(span.Minutes,2,0)&":"&numberformat(span.Seconds,2,0)
T trueboss323 Active Member Licensed User Longtime User Feb 23, 2015 #4 Thanks Erel. One more question. Is it possible to check if the time span is greater than another time span? I already used Code: Copy 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
Thanks Erel. One more question. Is it possible to check if the time span is greater than another time span? I already used Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Feb 23, 2015 #5 It is possible, but you will need to write the code that checks it. If you are only dealing with hours or smaller intervals then it is quite simple to convert the Period to seconds and then compare it: Code: Copy Sub ShortPeriodToSeconds(p As Period) As Int Return p.Hours * 3600 + p.Minutes * 60 + p.Seconds End Sub Upvote 0
It is possible, but you will need to write the code that checks it. If you are only dealing with hours or smaller intervals then it is quite simple to convert the Period to seconds and then compare it: Code: Copy Sub ShortPeriodToSeconds(p As Period) As Int Return p.Hours * 3600 + p.Minutes * 60 + p.Seconds End Sub