At first, I thought an 'uptime' for my server would be easy. Using Garry's Mod v10 lua command string.FormattedTime (found in his lua\extensions\string.lua)
However, I found it had two things wrong.
1) First and foremost, it displays the wrong time after more than 24 hours.
2) It didn't display days. I'd prefer days instead of milliseconds.
So, I wrote my own. Feel free to use this or any derivative of this in any code you wish.
Rewrite it if you wish to be able to pass your own time to it. It wouldn't be difficult to make it exactly like what string.FormattedTime was supposed to be.
As it is, it will use the time the server has been running.
Passing the function "full" will result in "# weeks, # days, # hours, # minutes, # seconds". "short" (or any other word) will result in "0#:0#:0#:0#:0# (w:d:h:m:s)"
function Umotd_GetUptime(fmt) -- Credit to Garry. Idea from lua\extensions\string.lua "FormattedTime" function. Though, his math ends up wrong at times.
local U_time = math.floor(os.clock{})
local w, d, h, m, s = 0,0,0,0,0
w = math.floor(U_time/604800)
U_time = U_time - (w*604800)
d = math.floor(U_time/86400)
U_time = U_time - (d*86400)
h = math.floor( U_time/3600 )
U_time = U_time - (h*3600)
m = math.floor( U_time/60 )
U_time = U_time - (m*60)
s = U_time
if fmt ~= "full" then return string.format("%02i:%02i:%02i:%02i:%02i",w,d,h,m,s) .. " (wk:d:hr:min:sec)"
else return w.. " weeks, " ..d .. " days, " .. h .. " hours, " .. m .. " minutes, " .. s .. " seconds."
end
end