I’m working on a date picker prompt for my game that allows the user to select a specific date and time. I’m having trouble converting the user defined dates into UTC time because for some reason os.time() does not return the correct hour on the client. UTC time is 6 hours ahead of my local time but for some reason os.time() is returning a value 2 hours ahead. I made a bug report here.
I’m working on an alternative in the mean time. I can’t seem to figure out how to get the time to offset properly based on the server time. For some reason the localDate variable ends up being 6 hours behind my local time.
--client
local timeOffset
Event.OnClientEvent:Connect(function(serverTime)
timeOffset = os.time() - serverTime
local UTC = os.time({year = Year, month = Month, day = Day, hour = Hour, min = Min ,sec = Sec}) + timeOffset
local localDate = os.date("*t",UTC)
end)
--Server
Event:FireAllClients(os.time())
EDIT: Thank you AbiZinho DateTime was just what I was looking for
If you are working for a specific date and time if u parse os.time() a dictionary with keys; year, month, day, hour, min, sec it will multiply the values out to the unix epoch. My point being here is you can have your players input that dictionary then compare it to other inputs players have made.
I investigated this and apparently you can do this:
local currentTime = os.time()
local UTC = os.date("!*t", currentTime)
local localDate = os.date("*t", currentTime); localDate.isdst = false -- gotta fix this lol
local diffTime = os.difftime(UTC, localDate)
No needing to fire the event to the server.
Oogling around StackOverflow:
On top of that, I can’t observe the error on the os.time(). Might have been a fluke. I’ll check again later.
Further testing indicate no error on the hours, cannot reproduce. Perhaps there’s an error on the machine?
I went looking further and only found out that this also should work:
local currentLocalTime = os.time(os.date("*t"))
local currentUTCTime = os.time(os.date("!*t"))
I’m really confused on why your time is displaying incorrectly.