Looking for a way to make an advanced clock

I have a daily login system, and I want to display the time like this.

hours : minutes : seconds

here is what I have so far, its a little bit messy but it works for the hours and the minutes.

--math that calculates hours left. in this case "Data" == the previous time they claimed.
math.floor((Data - (os.time() - 86400))/3600)
--the hour calculation is pretty simple, but the minutes is where it gets complecated.
((math.floor((Data - (os.time() - 86400))/400) * 400) - (math.floor((Data - (os.time() - 86400))/3600) * 3600))/400

both of these work fine. I am struggling with 2 things though.

number 1: I am a little confused on how to calculate seconds. It took me a while to figure out the minute calculation, and I am lost on getting the seconds :sweat_smile:

number 2: there is a small problem in the display.


in this picture you can see the hours and minutes displayed. they are displayed like 23 : 5. I would like them to be displayed like 23 : 05, if that makes sense. there is less then 10 minutes remaining and I want it to stay in the double digits, and just replace the first number with 0.

anyone know how to do either of these things? thanks in advance!

string.format("%02d : %02d", hours, minutes)

Assign the above to the TextLabel.

1 Like

Thank you, I haven’t used string.format, can you please explain what this snippet of code does?

string.format() formats values into a formatted string value, the format option %02d formats its corresponding value into a two digit integer with a single padded zero if that value is a single digit integer. The format string (the first argument) has two format options, both of which are %02d, as such we need to pass two additional values to the function which are to be formatted according to these options.

does i work replacing the d?
also whats the difference between those 2? is it the same?
local num = 12.2
local str = string.format("%i",num)
print(str)

The format options %d and %i are the same, in that they format values as integers, in your case print(str) would print 12.