Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get system time?

Asked by 9 years ago

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 <percent symbol>02d. It gets changed to d when I save edits or post the question

1 answer

Log in to vote
0
Answered by 9 years ago

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(),

Ad

Answer this question