subfighter Posted November 11, 2008 Posted November 11, 2008 i been looking in the help file and trying to figure out on how to convert duration of time from seconds to HH:MM:SS for example the durations are all stored in seconds 175 so how would i convert it hours:minutes:seconds so it would display the 175 seconds like the example below 00:02:55 any help appreciated. thanks
SandelPerieanu Posted November 11, 2008 Posted November 11, 2008 try this MsgBox(262144, '', Sec2Time(175)) Func Sec2Time($nr_sec) $sec2time_hour = Int($nr_sec / 3600) $sec2time_min = Int(($nr_sec - $sec2time_hour * 3600) / 60) $sec2time_sec = $nr_sec - $sec2time_hour * 3600 - $sec2time_min * 60 Return StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec) EndFunc ;==>Sec2Time faldo and MrVietA2 1 1
Varian Posted November 11, 2008 Posted November 11, 2008 I like that script psandu.ro...I use this when writing an encoding log to show the total time the process took expandcollapse popup;Usage Example MsgBox(0,'Time Difference is:', _FormatElapsedTime(175)) ;minutes MsgBox(0,'Time Difference is:', _FormatElapsedTime(38000)) ;hours MsgBox(0,'Time Difference is:', _FormatElapsedTime(450684)) ;days Func _FormatElapsedTime($Input_Seconds) If $Input_Seconds < 1 Then Return Global $ElapsedMessage = '' Global $Input = $Input_Seconds Switch $Input_Seconds Case 0 To 59 GetSeconds() Case 60 To 3599 GetMinutes() GetSeconds() Case 3600 To 86399 GetHours() GetMinutes() GetSeconds() Case Else GetDays() GetHours() GetMinutes() GetSeconds() EndSwitch Return $ElapsedMessage EndFunc ;==>FormatElapsedTime Func GetDays() $Days = Int($Input / 86400) $Input -= ($Days * 86400) $ElapsedMessage &= $Days & ' days, ' Return $ElapsedMessage EndFunc ;==>GetDays Func GetHours() $Hours = Int($Input / 3600) $Input -= ($Hours * 3600) $ElapsedMessage &= $Hours & ' hours, ' Return $ElapsedMessage EndFunc ;==>GetHours Func GetMinutes() $Minutes = Int($Input / 60) $Input -= ($Minutes * 60) $ElapsedMessage &= $Minutes & ' minutes, ' Return $ElapsedMessage EndFunc ;==>GetMinutes Func GetSeconds() $ElapsedMessage &= Int($Input) & ' seconds.' Return $ElapsedMessage EndFunc ;==>GetSeconds
subfighter Posted November 11, 2008 Author Posted November 11, 2008 CODE; enter the number of seconds below that will be converted to hh:mm:ss$sec = 278 ;seconds; there are 3600 seconds in an hour, so if we divide total seconds by 3600 and throw away the remainder, we've got the number of hours$Hours = int(int($sec) / 3600)If $Hours < 10 Then $Hours = "0" & $Hours; dividing the total seconds by 60 will give us the number of minutes, but we're interested in minutes past the hour: to get that, we need to divide by 60 again and keep the remainder$Minutes1 = int($sec / 60)$Minutes = int(mod ($Minutes1, 60))If $Minutes < 10 Then $Minutes = "0" & $Minutes; seconds are simple - just divide the total seconds by 60 and keep the remainder$seconds = mod ($sec, 60)If $seconds < 10 Then $seconds = "0" & $secondsMsgBox (4096, "Seconds Converted to HH:MM:SS", $Hours & ":" & $Minutes & ":" & $seconds)I figured it out from some PHP examples and my own touches but I think your is cleaner and leaner as it less lines of code psandu.rothanks again for your help..but
subfighter Posted November 11, 2008 Author Posted November 11, 2008 CODE$sec2time_hour = Int($vid_duration / 3600) $sec2time_min = Int(($vid_duration - $sec2time_hour * 3600) / 60) $sec2time_sec = $vid_duration - $sec2time_hour * 3600 - $sec2time_min * 60 $vid_duration = StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec) thanks i added your 4 lines of code above slightly modified and it worked great... thanks again for your help.
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