Hello! So today, I was thinking of making the lighting system and cool stuff to do with it. I decided to use os.date to get the time.
With this I made it so that the TimeOfDay in lighting is the current time.
I know there are probably other tutorials on this. I hardly checked for them. But right away I didn’t see any.
A few of you guys probably know how to do this already, but oh well.
while wait(60) do
local timeTable = os.date("*t", os.time()) -- Get the time table.
game.Lighting.TimeOfDay = timeTable.hour..":"..timeTable.min -- The time table is in dictionary format.
end
-- {year, month, day, yday, wday, hour, min, sec, isdst}
The isdst is a bool saying wether daylight savings time is on or off.
This is a very compact way of doing this with no math or using HTTPService.
It’s there free to take. It’s just the lines that get the time and set TimeOfDay(Edit: Model was a script, but now its a LocalScript so that in game it should work. When testing in studio server scripts work but in game the os.time is UTC I believe.). ^
I think using HttpService for something like this is unintuitive anyways.
Nice thing though! I had my game use Central European Time as the TimeOfDay but changed this in another update because it felt like I was disadvantaging people living on the other side of the world.
Is there anyway that we can set a specific timezone to be used for all players - instead of going off their local timezone? I’d be looking to just use the relevant UK timezone (GMT), rather than setting it per player.
Any advice would be greatly appreciated,
Thanks,
Jake.
You can use os.date() for this purpose, regardless of using it from a client or server.
Using the formatstring argument “!*t”, you’ll specify to get the time in UCT - which is the same as GMT, as far as get from a quick Google search - Make note of the exclamation mark before *t - without it, you’re basing the time off of the current device’s timezone, while having the exclamation mark makes the time UCT.
Your code seems to be using an incorrect format for the TimeOfDay property.
TimeOfDay expects a string following the hh:MM:ss format - that is, hours, minutes, seconds.
You can strip away the second argument of os.date, as seen in sircfenner’s post.
Also mind that this will just set the time once - if you want it to update over time, you’ll want to follow the examples in the first 3 posts of this thread.
local timeTable = os.date("!*t") -- Gets information about the current UCT time.
-- string.format with a format string to match the hh:MM:ss format, using TimeOfDay.
-- Alternatively you can use :SetMinutesAfterMidnight() or ClockTime.
game:GetService("Lighting").TimeOfDay = string.format("%0.2i:%0.2i:%0.2i", timeTable.hour, timeTable.min, timeTable.sec)
Apologies again, I have added the wait functions for one that updates over time but it doesn’t appear to work.
local timeTable = os.date(“!*t”) – Gets information about the current UCT time.
while wait(60) do
game:GetService(“Lighting”).TimeOfDay = string.format(“%0.2i:%0.2i:%0.2i”, timeTable.hour, timeTable.min, timeTable.sec)
end
Try making the local time table in the loop. Otherwise it probably won’t update.
while wait(60) do
local timeTable = os.date("!*t") – Gets information about the current UCT time.
game:GetService(“Lighting”).TimeOfDay = string.format("%0.2i:%0.2i:%0.2i", timeTable.hour, timeTable.min, timeTable.sec)
end
If your looking for utc time. I think a server script would work. Although if your using a local script make sure that your checking the clients TimeOfDay and not the servers(Due to FE). Like if your testing in game and using the command bar to check the time of day. It will display 14:00:00 if you haven’t changed it on the server.
OK, the updated script with the wait times (that you supplied earlier) do not appear to work, however, the one without the updating facility appears to work by setting the time once. It could be what you said and I’ll look into it now.