Help: Convert Seconds into Hour

Solved!! :slight_smile: Found a solution on other forums

It goes like this:

local function timeCount(numSec) local nSeconds = numSec if nSeconds == 0 then coolTime.text = "00:00:00"; else local nHours = string.format("%02.f", math.floor(nSeconds/3600)); local nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours\*60))); local nSecs = string.format("%02.f", math.floor(nSeconds - nHours\*3600 - nMins \*60)); coolTime.text = nHours..":"..nMins..":"..nSecs end end

Thanks for your time and effort guys :slight_smile:

Jam

It seems that I’ve just relived this thread trying to figure out how to convert the an arbitrary integer into hours, minutes and seconds and failing completely. Seems like this very basic function is entirely missing from Lua.

As mentioned above, your wrap_time() function is returning a table.  We just posted a tutorial a couple of weeks ago on printing tables:

http://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/

Converting seconds to hours is simply a matter of:

hours = math.floor( seconds / 360 )   – 60 seconds a minute, 60 min per hour… 60 x 60 = 360, truncate .

leftover_seconds = seconds - (hours * 360)

minutes = math.floor ( left_overseconds / 60 )

leftover_seconds = leftover_seconds - (minutes * 60)

print(hours … “:” … minutes … “:” … leftover_seconds)n

It seems that I’ve just relived this thread trying to figure out how to convert the an arbitrary integer into hours, minutes and seconds and failing completely. Seems like this very basic function is entirely missing from Lua.

As mentioned above, your wrap_time() function is returning a table.  We just posted a tutorial a couple of weeks ago on printing tables:

http://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/

Converting seconds to hours is simply a matter of:

hours = math.floor( seconds / 360 )   – 60 seconds a minute, 60 min per hour… 60 x 60 = 360, truncate .

leftover_seconds = seconds - (hours * 360)

minutes = math.floor ( left_overseconds / 60 )

leftover_seconds = leftover_seconds - (minutes * 60)

print(hours … “:” … minutes … “:” … leftover_seconds)n