local UTCTime = os.time()
local UTCDate = os.date("!*t")
print(UTCDate.hour) --> 17
print(os.date("%H", UTCTime)) -- not the same as UTCDate.hour
I am very confused on this os library.
According to the library, os.date 2nd argument is defaulted to the value of os.time, which is UTC time.
Furthermore, os.date("!*t") should also return the same value as os.time when converted to seconds, which is still UTC time.
Now, when I printed them, UTCDate.hour returns a number (example: 17)
For os.date("%H", UTCTime), I would assume it would also return the same (example: 17), but what it outputted is a different number.
Can someone explain this for me? I am very confused.
The problem is that os.date() with os.time() returns local time, see screenshot, this is so because os.time() uses local time, but since we play on the server, and we check the code in the studio, where there may be another time - there may be discrepancies
In studio
In Game
You can also try removing the !, as @RickAstll3y said, it will show you what’s with os.time(), what’s with os.date() is the local time, there shouldn’t be any problems in the game, but if you want to use it in local scripts, then I recommend either using os.time() or os.date("*t") so that players see the time in their time zone