I’m making a world exploration game and I want the time of day to be accurate with what it actually is. I don’t know how to get the time of other timezones than the player. Is there any way to do this?
This Would Get Time In All TimeZones I Guess
os.time
I was looking at os.time. From what I can tell it only gives the time of the operating system.
os.time on the server is different from os.time on the client.
os.time takes the client’s time, and os.time on the server just gives UTC time. And it’s best used for ban times, fall damage, etc.
You Can Use This May Help A Lot
When I printed the os.time("%X") it gave me the time in my timezone.
os.time()
gives the time in the UTC timezone. Does not matter your location or device you are using, it always gives the UTC timezone.
So you get the UTC time, and then add/subtract to it the difference between UTC and the other timezones to get the time in that timezone.
For example if a timezone is 5 hours ahead of UTC. Then you do os.time() + (5 * 60 * 60)
(converting hours into seconds).
Wrong. os.time
gives the UTC time on both client and server, they are not synced together though. The UTC time on the client may be a few seconds apart from the time on the server.
I am using os.time() in my script and it is giving me the EST time
“Returns how many seconds have passed since the Unix epoch (1 January 1970, 00:00:00), under current UTC time.”
It says on the documentation. I tested it myself and compared it with the UTC time online, it was same. I have never experienced issues with this before.
That returns nil for me I’ve tried it
Can you send me the code which returned nil?
Just tested again, with unix time on my browser, and printed it in Roblox Studio. Can confirm it is the same despite me living in a different timezone. There is a problem with your script.
this is the script:
print(DateTime.UnixTimestamp)
Did you read any of the posts here. I am talking about os.time()
.
can you just give me the script that you used. i read the posts above and i dont understand what im doing wrong
I got it to work by using tick() but I still don’t know what was wrong with os.time
I use this for EST time:
In my opinion, the fastest method for me is adding a certain amount of hours to get the timezone you want.
local EST = os.time()+18000
local t = os.date("!*t",EST)
heres the script i ended up using:
local timestamp = tick()+((8+time_offset) * 3600)
local exact = os.date("%I",timestamp)..":"..os.date("%M",timestamp).." "..os.date("%p",timestamp)
Hey! This is something I tried for showing the user’s time using os time!
local function to12H(hour)
hour = hour % 24
return (hour - 1) % 12 + 1
end
local function getTime()
local date = os.date("*t")
return ("%02d:%02d"):format(((date.hour % 24) - 1) % 12 + 1, date.min)
end
local AMIndicator = script.Parent.Parent.AMIndicator
local TimeLabel = script.Parent
while wait(1) do
local currentHour = os.date("*t")["hour"]
if currentHour < 12 or currentHour == 24 then
AMIndicator.Text = 'AM'
else
AMIndicator.Text = 'PM'
end
TimeLabel.Text = getTime()
end