Bug using os.date()

Hello, developers!

I’m currently using os.date to display the time a player is unbanned from my game, and it works perfectly fine in studio. For me now, the time is 20:35, and in studio, it says that I will be unbanned the next day at 20:35. But in-game it says 18:33, and I don’t know why. It’s still 20:35, but it doesnt say that in-game. I have checked that all durations of the ban were correct. Like, a day is 86400 seconds, and it says so in my script. But it still shows the wrong time. What is happening?

Do you call it from the server or client? The client will use the player’s time and the server will not.

Its called from the server. But the time is not the same in studio and in game.

Is a solution to take the time from the client and give it to the server?

it’s not a bug, os.date() returns UTC time, you can use format string "*t" to have it return local time instead

local values = os.date("*t", unbanTime)

1 Like

Thank you! I will fix this in my game.

1 Like

But how do I use this. I use %c in my game. Can I convert the time into local time, but still use %c and get a date? @0msh

what I would do is this

local banUntil = os.time() + 86400 --ban time

local unbanDate = os.date("*t", banUntil)
print("banned until " .. unbanDate["month"] .. "/" .. unbanDate["day"] .. "/" .. unbanDate["year"] .. " " .. unbanDate["hour"] .. ":" .. unbanDate["min"])

easy to understand and mimics the format of %c

1 Like

Thank you, this was very helpful. I’m a bit new to the os function.

I use *t and some code from the example you showed me. In studio, the unban date says 2022/06/2022 17:51:00, but in-game it says 2022/06/2022 15:51:00. What am I doing wrong? @0msh