Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lua function to convert seconds to a clock string
function SecondsToClock(seconds)
local seconds = tonumber(seconds)
if seconds <= 0 then
return "00:00:00";
else
hours = string.format("%02.f", math.floor(seconds/3600));
mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
return hours..":"..mins..":"..secs
end
end
@Hristiyanii

This comment has been minimized.

Copy link

Hristiyanii commented Oct 15, 2017

Hey, Sorry for 7 years old response, Thank you it works! :)

@diegorodriguesvieira

This comment has been minimized.

Copy link

diegorodriguesvieira commented Nov 7, 2017

Hahaha, thank you man! =)

@neves768

This comment has been minimized.

Copy link

neves768 commented Nov 26, 2017

7 fuckin' years? hahahaha lol

@RectangleEquals

This comment has been minimized.

Copy link

RectangleEquals commented Dec 5, 2017

Better late than never, I guess ¯\(ツ)

@IndianaBonesUrMom

This comment has been minimized.

Copy link

IndianaBonesUrMom commented Mar 7, 2018

Rated 5/5.

@TacticalBFG

This comment has been minimized.

Copy link

TacticalBFG commented Jun 1, 2018

8 years late but thank you for this

@ElPumpo

This comment has been minimized.

Copy link

ElPumpo commented Oct 30, 2018

Hahahaha

@FrBillyD

This comment has been minimized.

Copy link

FrBillyD commented Dec 17, 2018

😄 thanks !

@Majid110

This comment has been minimized.

Copy link

Majid110 commented Feb 7, 2019

Thank you

@SnowQT

This comment has been minimized.

Copy link

SnowQT commented Feb 13, 2019

never late :) 👍 thanks!

@JoBoDo

This comment has been minimized.

Copy link

JoBoDo commented May 27, 2019

Hey mate 9 years later but you helped me out. Thanks!

@notela

This comment has been minimized.

Copy link

notela commented Jul 8, 2019

thank you man!

@BennyFaelz

This comment has been minimized.

Copy link

BennyFaelz commented Jul 8, 2019

Nice

@chatainsim

This comment has been minimized.

Copy link

chatainsim commented Oct 3, 2019

Thanks!

@CarlosDSF

This comment has been minimized.

Copy link

CarlosDSF commented Oct 7, 2019

Thanks bro!

@MRePotatoes

This comment has been minimized.

Copy link

MRePotatoes commented Oct 22, 2019

now this, this is gold

@aveadrin

This comment has been minimized.

Copy link

aveadrin commented Nov 23, 2019

thx!!!!

@PotatoTheWorker

This comment has been minimized.

Copy link

PotatoTheWorker commented Mar 2, 2020

Cheers.

@ObserverOfTime

This comment has been minimized.

Copy link

ObserverOfTime commented Apr 17, 2020

Here's a trick:

os.date('!%H:%M:%S', seconds)
-- better yet
os.date('!%T', seconds)

Explanation:

os.date ([format [, time]])

Returns a string or a table containing date and time, formatted according to the given string format.

If the time argument is present, this is the time to be formatted. [...]

If format starts with !, then the date is formatted in Coordinated Universal Time. [...]

@debagos

This comment has been minimized.

Copy link

debagos commented May 21, 2020

@ObserverOfTime
nice trick! thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.