-- September 16th, 1998 at 11:48:10 PM:
local timestamp = 906000490
local t = os.date("*t", timestamp)
-- Produces the following table, t:
-- {year = 1998, month = 9, day = 16, yday = 259, wday = 4,
-- hour = 23, min = 48, sec = 10, isdst = false}
isdst would be a boolean describing if daylight savings time is currently active. However, when I run this code in studio and check the results, it returns false? We are currently in daylight savings time if I am not mistaken?
I did a quick test and from my results, if you are using "!*t" for the formatting, it print false for isdst, even if Daylight Savings Time is in effect, but if you use "*t", aka local time, it’ll correctly identify it. I had this code in a script
local utc = os.date("!*t",os.time())
local loc = os.date("*t",os.time())
print(utc.isdst)
print(loc.isdst)
Adding on to your answer UTC does not have DST and therefore would always respond with false:
UTC does not change with a change of seasons, but local time or civil time may change if a time zone jurisdiction observes daylight saving time or summer time. - Wikipedia
Thank you! I decided to try this, in studio it indeed prints true as you’re the “server”. However on a running gameserver that also prints “false”… How would I try to find this out?
Just tried doing print(os.date("*t",tick()).isdst) on both the client and server and got the same answer (true) not sure what you are doing differently, if you could provide more information (screenshots, etc) that would be helpful.
I don’t know what you must do exactly to make it work for serversided scripts, but you could make a RemoteEvent to pass in isdst and do something with that information. You’ll probably need some checks as well if you don’t want people to fake being in DST or not, but up to you
I don’t think doing this is the best way going forward because you don’t take to account where the player is in the world, DST does not start at the same time in every country depending on where your player is the result will not be consistant.
It’s dependent on what @OP wants to do specifically, if he wants to do something when a player is in DST, then it should work just by using a RemoteEvent and passing it if they’re in DST or not. But if it’s something that is done for the entire server, even if some player are not in, then the only real way is to do the manual method as @OP mentioned as I was typing it haha
I tested it out right now using what @LearnCSharp, and I’m not sure if I did anything wrong but it wasn’t working for me,
(Server Script)
My code
local utc = os.date("!*t",os.time())
local loc = os.date("*t",os.time())
local utcloc = os.date("*t",os.time(utc))
print("UTC: ",utc.isdst)
print("Local: ",loc.isdst)
print("UTC Local: ",utcloc.isdst)
I even tried commenting out the loc lines and it still didn’t work for me. I probably did something wrong so I also tried directly copying and pasting what they did and adding pritn statements, and they sitll both printed false
I think at this point your best bet is to manually set a variable since I don’t think it’s possible for a server script to be able to get DST
Sorry!
This thing has been quite a headache especially with different behavior between studio and the live game, I agree by now just using a value that is manually set would be the best way going forward.
local weekdayNumber = tonumber(os.date("%w"))
local daysSinceSunday
if weekdayNumber == 7 then
daysSinceSunday = 0
else
daysSinceSunday = weekdayNumber
end
local monthNumber = tonumber(os.date("%m"))
local dayOfMonth = tonumber(os.date("%d"))
local isDaylightSavingsTime
if (monthNumber > 3 and monthNumber < 11) or ((monthNumber == 3 and dayOfMonth >= 8) and
(daysSinceSunday == 0 or dayOfMonth >= 14)) or ((monthNumber == 11 and dayOfMonth < 7 and
daysSinceSunday > 0)) then
isDaylightSavingsTime = true
else
isDaylightSavingsTime = false
end