Sign in to follow this  
Followers 0
SpookMeister

Function To Convert Miliseconds Into Readable Time

8 posts in this topic

I tried looking for this the other day, and couldnt find exactly what I was looking for so I wrote my own. I'm posting it here in the hopes that if no-one else needs it... well, at least I'll be able to find it again the next time I do :)

$begin = TimerInit()
Sleep(3000)
$dif = TimerDiff($begin)
$sTime = _TimeReadable($dif)
MsgBox(0, "Elapsed Time", $sTime)

Func _TimeReadable($mili)
    $TotalSeconds = Int($mili / 1000); convert miliseconds to seconds
    $Hours = Int($TotalSeconds / 3600); 3600 seconds in an hour
    $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60); 60 secs per min
    $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)); leftovers
    If $Hours < 10 Then $Hours = "0" & $Hours
    If $Minutes < 10 Then $Minutes = "0" & $Minutes
    If $Seconds < 10 Then $Seconds = "0" & $Seconds
    $FormattedTime = $Hours & ":" & $Minutes & ":" & $Seconds
    Return $FormattedTime
EndFunc  ;==>_TimeReadable

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites



nice , but i dont get the point of it.. you never use more then sleep(60000) (60 seconds) ..

but again , nice


-jaenster

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The whole top part was just to demonstrate. In my case I was creating a recording application, and I wanted to display how long the recording took.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

I tried looking for this the other day, and couldnt find exactly what I was looking for so I wrote my own. I'm posting it here in the hopes that if no-one else needs it... well, at least I'll be able to find it again the next time I do :mellow:

$begin = TimerInit()
Sleep(3000)
$dif = TimerDiff($begin)
$sTime = _TimeReadable($dif)
MsgBox(0, "Elapsed Time", $sTime)

Func _TimeReadable($mili)
    $TotalSeconds = Int($mili / 1000); convert miliseconds to seconds
    $Hours = Int($TotalSeconds / 3600); 3600 seconds in an hour
    $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60); 60 secs per min
    $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)); leftovers
    If $Hours < 10 Then $Hours = "0" & $Hours
    If $Minutes < 10 Then $Minutes = "0" & $Minutes
    If $Seconds < 10 Then $Seconds = "0" & $Seconds
    $FormattedTime = $Hours & ":" & $Minutes & ":" & $Seconds
    Return $FormattedTime
EndFunc ;==>_TimeReadable
:) Isn't this the same as _TicksToTime() ?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Sigh, leave it up to me to re-invent the wheel. Yeah, the same functionality is in _TicksToTime. I didn't even think to look at it.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

If you need a nicely formatted time which include milliseconds (h:mm:ss.mmm):

 
  $ms = {wherever you get your milliseconds from} 
  $time = StringFormat("%d:%.2d:%06.3f", (Floor($ms / 3600000)), (Floor(Mod($ms,3600000) / 60000)), (Mod(Mod($ms,3600000),60000) / 1000))
 

Share this post


Link to post
Share on other sites

zaNergal,

Please look at the date of the threads before you post in future - this one dates from over 7 years ago. :o

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0