I want to print my own timezone using os.date("%Z")
But I cannot do it because it gets obscured. (screenshot)
This may be caused by my system using Russian language but I’m not really sure because output prints cyrillic just fine. I’ve asked about this months ago but at that time I abandoned it because I decided to go with a workaround, there isn’t any more information about this that I could find on the devforum.
What is this caused by and how do I make it print it out as comprehensible characters?
local timezone = os.date("%Z")
local test = os.date("%W %w %Y %A")
print(timezone, test)
output
15:10:14.681 Classic Baseplate auto-recovery file was created - Studio
15:10:34.223 ������������� ����������� ����� 38 5 2022 Friday - Client - LocalScript:4
The %z gives you the timezone, this may be sufficient for your needs, however please note:
One cannot use os.date("%z") as the format of its return value is non-portable; in particular, Windows systems don’t use the C99 semantics for strftime(). - lua-users wiki: Time Zone
Which means using %z would just give u something that ROBLOX cannot render as a string, hence why the output does that.
In order to get the timezone as a string, then, you’ll do:
-- LocalScript
local timezone = os.date("%m/%d/%y at %H:%M:%S", os.time())
print(timezone)
-- ServerScript
local function getServerTimeZone(hourOffset, minutesOffset, dst:boolean?)
local hoursToSeconds = (hourOffset) * 3600 -- this is how you can make timezones
local minutesToSeconds = minutesOffset * 60
if dst then
hoursToSeconds = (hourOffset + 1) * 3600
end
return os.time() + hoursToSeconds + minutesOffset
end
local timezone = os.date("%m/%d/%y at %H:%M:%S", getServerTimeZone(5, 1))
print(timezone)
Output
09/23/22 at 08:36:52 -- For both, assuming you're still using the same setup with no change.
So from what I understood here it is simply gonna be impossible for me to print the timezone because Windows simply can’t provide it in a way that Roblox can render? That’s weird because normally it should just give you whatever your system timezone is as the output. (It did that for me saying my timezone is RTZ 7 before I changed my system language.). Regardless, thanks for the reply! I guess I will use %z instead of %Z and print the timezone as UTC±