Jump to content

Function To Convert Miliseconds Into Readable Time


SpookMeister
 Share

Recommended Posts

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

  • Developers

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() ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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]

Link to comment
Share on other sites

  • 7 years later...

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))
 
Link to comment
Share on other sites

  • Moderators

zaNergal,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...