Is this how os.Date works?

basically I wanted to know something, if I used os.Time in one server, and os.Time in another server, would they be the same timezone? Or does it depend on where the server was created or something, not exactly sure how it works

1 Like

Nah, it’s the same because os.time gets you the time in this timezone: UTC.

os.time gets you time in UTC timezone.

so itll always give you the UTC timezone? Thanks!

I’m not sure about os.date tho. Probably returns time based on the server’s timezone, which is also in UTC.

Ok also, with os.Date how do I get the day, month, and hour, and nothing else?

os.date returns the Weekday, Month, Day, Time and Year and they’re all combined into strings so you’ll have to split them in some way.

You can add arguments in the function and there are two values that makes the function return something.

If you do os.date("*t"), it will return something like this:

{
["day"] = 9,
["hour"] = 3,
["isdst"] = true,
["min"] = 0,
["month"] = 8,
["sec"] = 21,
["wday"] = 4,
["yday"] = 221,
["year"] = 2023
}

If you do os.date("!*t"):

{
["day"] = 9,
["hour"] = 1,
["isdst"] = false,
["min"] = 0,
["month"] = 8,
["sec"] = 21,
["wday"] = 4,
["yday"] = 221,
["year"] = 2023
}

Oh great! So once I do

os.date(“*t”)

it will give me all of these values?
so would I just do

os.date(“*t”)[‘Day’]

to get the day? Or is there another way to do this?
Thanks!

Idk another ways, this is the only way I know.

os.time returns the current epoch timestamp in UTC.

os.date will return the current date formatted the way you specify. If no format is specified, it will instead return the same thing os.time returns.

For example, os.date(%B) will return the full name of the current month. You can make os.date format an epoch timestamp as well.

Clock Script

local Time = os.date(%I)..":"..os.date(%M)..":"..os.date(%S)

while task.wait(1) do
     Time = os.date(%I)..":"..os.date(%M)..":"..os.date(%S)
     print(Time)
end

Click here and scroll down to learn more.
If this post was helpful, please mark it as a solution!

1 Like