So my issue about this post is that I want to show an irl time zone in the game. But when I have my script in the game it kind of works. When I change my time on my phone and joined the game, it showed the phones local time. I’ve looked through forums and didn’t find a solution, I know there might be one out there, not sure. Can someone help out?
local RunService = game:GetService("RunService")
local Icon = require(game:GetService("ReplicatedStorage").Icon)
local icon = Icon.new()
:align("Center")
:lock()
local res
local function MilitaryToStandard(hour)
return if hour > 12 then hour - 12 else hour, if hour > 12 then true else false
end
local function ConvertTo2Digit(digit)
return if #tostring(digit) < 2 then 0 .. digit else digit
end
RunService.Heartbeat:Connect(function()
local date = os.date("!*t", os.time() + (3600 * -4)) -- if i changed the -4 to
local min = ConvertTo2Digit(date.min) -- another number,
local hour, isPM = MilitaryToStandard(date.hour) -- it changes time
local sec = ConvertTo2Digit(date.sec)
if hour == 0 then
hour = 12
end
local result = "EST TIME ".. hour .. ":" .. min ..":" .. sec
res = result
icon:setLabel(result, "deselected")
end)
No, it returns a server-synchronized Unix timestamp.
This function is useful for creating synchronized experiences, as it has three properties necessary for doing so: it's a real-world time clock, it's monotonic, and it has decent precision.
Unless you go outside of Roblox such as a web service that can get the time zone based off IP,
Roblox uses the sever time. You can use an offset from the server time however.
This script shows the current server time with UTC offset
local timeZoneOffset = os.date("%z")
local currentTime = os.date("*t")
print(string.format("%02d:%02d:%02d UTC%s", currentTime.hour, currentTime.min, currentTime.sec, timeZoneOffset))
If you want EST time specifically, EST is UTC - 5, so 5 hours behind UTC. However, removing 5 hours from UTC will not work when daylights savings is being used (in the summer), because it then becomes UTC -4
You might be able to retrieve the current EST unix time from an http request