# Function To Convert Miliseconds Into Readable Time

## 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)
MsgBox(0, "Elapsed Time", \$sTime)

\$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

##### 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 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

##### 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

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

\$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
Isn't this the same as _TicksToTime() ?

Live for the present,
Dream of the future,
Learn from the past.

##### 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.

##### 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.

I did similar here: http://www.autoitscript.com/forum/index.ph...opic=8492&st=15

2015 - Still no flying cars, instead blankets with sleeves.

##### 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 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.

M23

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

##### Share on other sites
This topic is now closed to further replies.

×

• Wiki

• Back

• Git