Another way of thinking:
You probably want to calculate the remaining time. So why not use the clicks? You have the start time and a defined time until the end. So the start time must be recorded and the end time (start time + running time in clicks). Both are click values that can be quickly analysed and converted using Date.Time functions without having to experiment with different string formats.
I use this principle to give apps a limited lifetime. If the end time is exceeded, the app closes immediately after starting for instance.
I think you need to split hours and minutes... using datetime and ticks you can convert to anything you want but not have in mind hh:mm is wrong because the limit 23:59..
Tip: don't use DateTime methods for this. Explanation in the video tutorial about date & time.
B4X:
Sub AppStart (Args() As String)
Dim d1 As Long = 60.5 * DateTime.TicksPerHour
Dim d2 As Long = ConvertHHMMToMilliseconds("10:30")
Dim d3 As Long = d1 - d2
Log(ConvertMillisecondsToString(d3))
End Sub
Sub ConvertMillisecondsToString(t As Long) As String
Dim hours, minutes As Int
hours = t / DateTime.TicksPerHour
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
Return $"$1.0{hours}:$2.0{minutes}"$
End Sub
Sub ConvertHHMMToMilliseconds (s As String) As Long
Dim m As Matcher = Regex.Matcher("(\d+):(\d+)", s)
m.Find
Dim hours As Int = m.Group(1)
Dim minutes As Int = m.Group(2)
Return hours * DateTime.TicksPerHour + minutes * DateTime.TicksPerMinute
End Sub
If you calculate with absolute (unique) tick values (date & time), it should work.
Of course, this does not work with "times" that are then somehow subsequently assigned to a string that was obtained from a tick value.
The basis must always be the tick value itself. Then you can also calculate a tick value in the future and the duration. If you put both values in relation to each other, it works wonderfully.
Calculating with ticks will work. Converting time strings with DateTime.Time or the parse methods will not work (in some cases) as those strings represent a specific time instance and not duration.
Sub ConvertMillisecondsToString(t As Long) As String
Dim hours, minutes As Int
hours = t / DateTime.TicksPerHour
minutes = Abs((t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute) '-> Abs ??
Return $"$1.0{hours}:$2.0{minutes}"$
End Sub
Sub ConvertMillisecondsToString(t As Long) As String
Dim sign As String = IIf(t < 0, "-", "")
t = Abs(t)
Dim hours, minutes As Int
hours = t / DateTime.TicksPerHour
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
Return $"${sign}$1.0{hours}:$2.0{minutes}"$
End Sub