View Full Version : Display Girder Uptime

November 6th, 2008, 10:21 PM
Found part of this somewhere on the board. Modified it some to make it more user friendly.

local seconds = win.GetElapsedSeconds ()
local hour = string.format("%02.f", math.floor(seconds / 3600))
local min = string.format("%02.f", math.floor(seconds / 60 - (hour * 60)))
local sec = string.format("%02.f", math.floor(seconds - hour * 3600 - min * 60))
local uptime = string.format('Girder has been running for %d hours %d minutes and %d seconds', hour, min, sec)
print (uptime)

Will display something similar to: Girder has been running for 0 hours 9 minutes and 36 seconds

Rob H
November 7th, 2008, 01:45 AM
Hmm... that shouldn't work!

Not using %d in the string.format at least. %s would be fine and would retain the formatting.

November 26th, 2008, 05:03 PM
It formats it differently Rob...

Using %d...
Girder has been running for 1 hours 57 minutes and 1 seconds

Using %s..
Girder has been running for 01 hours 59 minutes and 03 seconds

%s includes a preceeding 0 if needed it seems where %d doesn't.

Rob H
November 27th, 2008, 03:59 AM
That's what I would have expected since harleydude was already converting to a string using the "%02.f"

Presumably what is happening is that the Lua runtime (or maybe the standard C runtime) is converting back to numeric form and then using that for the output.