Given a Time String of "01:00:00", how would I calculate the number of seconds contained within the time presented? For example, the string shown represents an hour of time. I need to find out how to convert this time to 3600 seconds.
Dim timestr As String = "01:00:00"
DateTime.TimeFormat = "HH:mm:ss"
Dim time As Long = DateTime.TimeParse(timestr)
Dim seconds As Int = ((DateTime.GetHour(time)*3600) + (DateTime.GetMinute(time)*60) + DateTime.GetSecond(time))
Log(seconds)
Dim timestr As String = "01:00:00"
DateTime.TimeFormat = "HH:mm:ss"
Dim time As Long = DateTime.TimeParse(timestr)
Dim seconds As Int = ((DateTime.GetHour(time)*3600) + (DateTime.GetMinute(time)*60) + DateTime.GetSecond(time))
Log(seconds)
I don't recommend using DateTime features for values that do not represent specific time instances (time instance example: February 8, 1999 12:34:56).
You will encounter all kinds of unexpected issues.
You can use this method to parse the time period:
B4X:
Sub HHMMSSToPeriod (time As String) As Period
Dim p As Period
Dim m As Matcher = Regex.Matcher("(\d\d?):(\d\d):(\d\d)", time)
If m.Find Then
p.Initialize
p.Hours = m.Group(1)
p.Minutes = m.Group(2)
p.Seconds = m.Group(3)
End If
Return p
End Sub
Dim p As Period = HHMMSSToPeriod("01:23:45")
Log(p)