DataTime in TimeOfDay not working [Solved]

You can write your topic however you want, but you need to answer these questions:

  1. Hey guy’s so i need to my script change the TimeOfDay to the real time clock usin DataTime.now()

  2. but when i test it the TimeOfDay go to 00:00

  3. i try others type of LTS

local dt = DateTime.now()
local TimeChange = dt:FormatLocalTime("LTS", "zh-cn")

while wait(1) do
	game.Lighting.ClockTime = TimeChange
end

i dont know what to do ;( can some one help me pls

sorry for my bad english

ClockTime requires a number representing the hour, you want game.Lighting.TimeOfDay = TimeChange.

Another issue you will run into is when you create the dt and TimeChange variable the values are copied into place and will not change without another = assignment. Since they are outside of the while loop they will never change and neither will your TimeOfDay. Move them into the while loop like so

while task.wait(10) do
	local dt = DateTime.now()
	local TimeChange = dt:FormatLocalTime("LTS", "zh-cn")

	game.Lighting.TimeOfDay = TimeChange
end
1 Like

Hi thanks but i tried your script but the time go to 14:30 and after 10 seconds turn in 00:00

Right, you need to use TimeOfDay instead of ClockTime

1 Like

now is working thankss bro
:smiley: i apreciate it

hey gertkeno just a question, how can i set the time in another country or time zone

I think you could use ToUniversalTime add/subtract as many hours difference and create a new DateTime with DateTime.fromUniversalTime this will not take daylight savings into account though.

local myTime = DateTime.now()
-- convert to UTC-0
local utc = myTime:ToUniversalTime()
-- convert UTC-0 to UTC-6
local cst = DateTime.fromUniversalTime(utc.Year, utc.Month, utc.Day, utc.Hour - 6, utc.Minute, utc.Second)
-- read converted value
TimeOfDay = cst:FormatLocalTime("LTS", "zh-cn")
1 Like

thanks it works :>
i is good :nerd_face:

hey gertkneo :dotted_line_face:
i was trying it on the game and the script not work ; (

edit: now its works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.