How can I do a (large-time) timer?

I want to achieve a timer, like Jailbreak’s season timer:
lol
Just like Jailbreak, I want to achieve a timer for BIG amount of days, example 50
So far I just searched devforum, and didnt found out solution of my question.

First off, once the days get closer, you might want to have a specific time zone you’d like to use for this idea.

This can be achieved using os.time functions. Let me know if you need more help regarding the usage.

2 Likes

By using os.time, lets say, I made an example just to see how to use it.
i forgor

local targettime = 1644255084
while wait(1) do
	print(os.time())
	print(os.time() - targettime)
end

It works!
Only problem is I don’t know how to format it to days and minutes.

…or if the number is negative, it may not be good

1 Like

Vinny’s post is the solution.

Here is some clarification:

  • os.time returns the time in seconds since the unix epoch

This means you can calculate a future time like this:

local eventTime = os.time + numberOfSecondsInFuture

And you can calculate the time until the event time with:

timeUntil = eventTime - os.Time

Then you can turn the time in seconds into the time in hours/days with some math.

Edit:

I think this code should work:

local timeSeconds = os.time() - targettime

local days = timeSeconds/(60*60*24)
local hours = (days%1)*60*60
hours = math.floor(hours)
days = math.floor(days)

The number is negative when it’s in the past

2 Likes

In that case, I would suggest using os.date instead.

Here is the API for that. Let me know if you need help with it, I’m here to help.

2 Likes

Use DateTime:

local now = DateTime.now() -- Current DateTime
local goal = DateTime.fromUniversalTime(2022, 6, 15) -- June 15th, 2022

-- Determine if past the goal time
if now.UnixTimestamp - goal.UnixTimestamp >= 0 then
    -- Past the goal time
end
1 Like
local eventTime = os.time() + 864000
while wait(1) do
	timeUntil = eventTime - os.time()
	result = os.date("%d days %H hours %M minutes %S seconds left", timeUntil)
	print(timeUntil)
	print(result)
end

I have one question.
How to actually make it not reset after player left/joined? (make it save)
After player joined:


After player rejoined:

1 Like

If you know the date of your event (which you do), set the eventTime variable to the following:

local eventTime = os.time({year=2022, month=3, day=14})
3 Likes

My final solution.
It’s working.

local eventTime = os.time({year=2022, month=2, day=9})
while wait(1) do
	timeUntil = eventTime - os.time()
	result = os.date("%d days %H hours %M minutes %S seconds left", timeUntil)
	print(timeUntil)
	print(result)
end

Thank you so much for helping me doing this.

2 Likes

Have a good night, and good luck :heart:

3 Likes