Has anyone mad a function that allows the programmer to pass seconds into it and have it return just the seconds portion?
For exaple, a function called fcnNumberOfSeconds:
B4X:
Sub fcnNumberOfSeconds (intSeconds As Int) As Int
Dim intReturnValue As Int = 0
' Code to extract just the seconds from the number passed in.
'------------------------------------------------------------
Return intReturnValue
End Sub
Let's say the number passed to it is 95 which is 1 minute 35 seconds. I'm looking for the function to return the number 35.
Sub ConvertTicksToTimeString(t As Long) As String
Dim hours, minutes, seconds As Int
hours = t / DateTime.TicksPerHour
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
Return NumberFormat(hours, 2, 0) & " hours, " _
& NumberFormat(minutes, 2, 0) & " minutes and " & NumberFormat(seconds, 2, 0) & " seconds"
End Sub
B4X:
Dim ticks As Long = 95 * DateTime.TicksPerSecond
Log(ConvertTicksToTimeString(ticks)
Sub ConvertTicksToTimeString(t As Long) As String
Dim minutes, seconds As Int
minutes = t/60
seconds = t - minutes * 60
Return NumberFormat(minutes, 2, 0) & ":" & NumberFormat(seconds, 2, 0)
End Sub
Sub ConvertTicksToTimeString(t As Long) As String
Dim hours, minutes, seconds As Int
hours = t / DateTime.TicksPerHour
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
Return NumberFormat(hours, 2, 0) & " hours, " _
& NumberFormat(minutes, 2, 0) & " minutes and " & NumberFormat(seconds, 2, 0) & " seconds"
End Sub
B4X:
Dim ticks As Long = 95 * DateTime.TicksPerSecond
Log(ConvertTicksToTimeString(ticks)
Private Sub ConvertTicksToTimeString2(t As Long) As String
Dim Hours, Minutes, Seconds, Milliseconds As Int
Hours = t / DateTime.TicksPerHour
Minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
Seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
Milliseconds = t Mod 1000
Return $"$2.0{Hours}:$2.0{Minutes}:$2.0{Seconds}:$2.0{Milliseconds}"$
End Sub
(To be moved/copied in the snippet forum?) P.S. Done, added to the original one