I am trying to make a timer until midnight of the current day, but I do not know how. Could I do something with os?
1 Like
os.date(time) returns a table with a lot more information including the second, minute, day and hour of the time
.
For a more simple solution, os.time started on midnight of January 1 1970, so whenever its divisible by the amount of seconds in a day, a new day has just started.
os.time()%(#secondsinaday) = time left until a new day. You could also add or subtract from os.time() based on the timezone if you want the entire game synced to EST for example.
2 Likes
Here’s a function you could use to find the time until midnight.
local function FindTimeTillMidnight()
local function FilterTime(n) -- makes time appear as (Ex. 04 and not 4)
if 10 > n then
return "0"..n
else
return n
end
end
local CurrentTime = os.date
local Hours = FilterTime(23 - CurrentTime("%H"))
local Minutes = FilterTime(59 - CurrentTime("%M"))
local Seconds = FilterTime(59 - CurrentTime("%S"))
return Hours, Minutes, Seconds
end
Are you referring to an in-game day in Roblox or real life?