Info Posted July 5, 2010 Share Posted July 5, 2010 (edited) $i = 3665.65;1 hour, 1 minute, 5seconds, 65 milliseconds MsgBox(0, "", _SecondsToTime($i)) Func _SecondsToTime($seconds, $msCount = 2) Local $h, $m $h = _AddZero(Int($seconds / 3600)) $seconds -= 3600 * $h $m = _AddZero(Int($seconds / 60)) $seconds -= 60 * $m If $msCount = 0 Then $seconds = _AddZero(Int($seconds)) ElseIf $msCount = 1 Then $seconds = _AddZero(Int($seconds)) & "." & StringTrimLeft(_AfterDot($seconds, $msCount), StringInStr(_AfterDot($seconds, $msCount), ".")) Else $seconds = _AddZero(Int($seconds)) & "." & _AddZero(StringTrimLeft(_AfterDot($seconds, $msCount), StringInStr(_AfterDot($seconds, $msCount), "."))) EndIf Return $h & ":" & $m & ":" & $seconds EndFunc ;==>_SecondsToTime Func _AddZero($data) Return StringFormat("%02d", $data) EndFunc ;==>_AddZero Func _AfterDot($data, $after) Return StringLeft($data, StringInStr($data, ".") + $after) EndFunc ;==>_AfterDot Maybe someone will search for this in the future. Edited July 8, 2010 by Info Link to comment Share on other sites More sharing options...
wraithdu Posted July 6, 2010 Share Posted July 6, 2010 Not debating usefullness here, but for code clarity: Func _AddZero($data) While StringLen($data) < 2 $data = "0" & $data WEnd Return $data EndFunc ;==>_AddZero Link to comment Share on other sites More sharing options...
trancexx Posted July 6, 2010 Share Posted July 6, 2010 Not debating usefullness here... Cool. Maybe StringFormat("%02d", $data) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
wraithdu Posted July 6, 2010 Share Posted July 6, 2010 One-upped again... dammit Link to comment Share on other sites More sharing options...
Malkey Posted July 8, 2010 Share Posted July 8, 2010 (edited) Good luck in understanding the resultant StringFormat control of "%05.2f" for 2 decimal places, and "%02.0f" for no decimal places. And the role that "($iDecPlaces > 0)" plays. It is simple if you know. $i = 3665.65 ; 1 hour, 1 minute, 5seconds, 650 milliseconds MsgBox(0, "", _SecondsToTime($i, 2)) Func _SecondsToTime($secs, $iDecPlaces = 0) If $iDecPlaces < 0 Then $iDecPlaces = 0 Return StringFormat("%02d:%02d:%0" & (2 + ($iDecPlaces > 0) + $iDecPlaces) & "." & $iDecPlaces & "f", _ ; ($iDecPlaces > 0) allows for decimal point. Int($secs / 3600), _ ; Hours Int(Mod($secs, 3600) / 60), _ ; Minutes $secs - (Int($secs / 3600) * 3600 + Int(Mod($secs, 3600) / 60) * 60)) ; Seconds EndFunc ;==>_SecondsToTime Edited July 10, 2010 by Malkey Link to comment Share on other sites More sharing options...
gazai Posted July 23, 2010 Share Posted July 23, 2010 Excellent script! I was about searching for such function a few days ago. One suggest: what about adding a reverse function to it (time-to-seconds) to make it perfect? Frankly, I tried and failed. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now