Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get system time?

I found this script in the Roblox forum:

			local TIME = tick()
			local secs = TIME % 60
			local mins = math.floor((TIME % 3600) / 60)
			local hrs = math.floor((TIME % (3600*24) / (3600*24)) )
			local TIMESTR = string.format("d:d:d", hrs, mins, secs)
			print(TIMESTR)

But the hour value is always 00. Can anyone help me fix that or tell me a better way to get system time?

Also string.format("d:d:d", hrs, mins, secs) should be 02d. It gets changed to d when I save edits or post the question

1 answer

✓ Accepted answer

The tick() method will give you the number of seconds that have passed since the UNIX epoch (January 1st, 1970)

Since ROBLOX servers are hosted in different time zones, you might want to use the HTTPService to find the current date and time. For example, you could use http://www.timeapi.org/utc/now which would always show up in the UTC time zone. Depending on which one you use, you can have the API do the string formatting for you.

To get the current time in the Time Zone that the server is being hosted in, you can use os.date() and os.time(),

This discussion is preserved as it was. New answers, comments, and votes are closed.