I want to get the players time zone to know when a player chats in my chat system. I am using text labels so it should be simple. I cant seem to find any posts on this so anything helps. I know how to get the time so just need their time zone like EST or PST. Thanks for coming by!
Well, there is a library called “os”, you can use it for that kind of stuff, you can just do something like
os.date( “%a %b %d, %H:%M”) --output: Wed Mar 16, 09:33
i hope it helps you!
you can find more info here link
I would like to add that this code should be used on the client for it to work (prevent confusion).
Am I able to abbreviate it? To just the 3 letters?
If you look at the docs here, you can see that you can get the player’s local time using a LocalScript. You can then compare that local time with the UTC/GMT time, and then calculate the time differences (timezone) that way.
It sure is! I will get some code prepared for you now.
Well yes but I dont want the time, just the zone the player in to show to others what time zone they are.
This will make the abbreviation:
local abbreviation = ''
for i, v in pairs(tostring(os.date("%Z")):split(' ')) do
abbreviation = abbreviation.. v:sub(1,1)
end
print(abbreviation)
Made a whoopsie in my code… this is now compatible with UTC.
local abbreviation = ''
if #tostring(os.date("%Z")) ~= 3 then
for i, v in pairs(tostring(os.date("%Z")):split(' ')) do
abbreviation = abbreviation.. v:sub(1,1)
end
else
abbreviation = os.date("%Z")
end
print(abbreviation)