Day/Night Cycle and Daylight Savings Time

Hello!

I put a real time day/night cycle script into my game, and I’m just now realizing that it never updated with daylight savings time a couple of weeks ago. For instance, if it’s 6:00 PM, it’ll be already dark out in the game while it’s still light out in real time. How do I update the script?

while true do	
	local dateTime = DateTime.now()
	local universalTime = dateTime:ToUniversalTime()
	universalTime.Hour -= 5
	local estTime = DateTime.fromUniversalTime(universalTime.Year, universalTime.Month, universalTime.Day, universalTime.Hour, universalTime.Minute, universalTime.Second, universalTime.Millisecond)
	game.Lighting.TimeOfDay = estTime:FormatUniversalTime("HH:mm:ss", "en-us")
	wait(60)
end

This line looks like your current time zone is set as 5 hours behind UTC.

universalTime.Hour -= 5

So I would set this to:

universalTime.Hour -= 4
1 Like