I'd like to go further and expand on Kiriot's answer.
os.time() returns UTC time, which is (roughly) the same accross all computers around the world at the same time, regardless of time zones.
tick() returns local time; that is, time as set by the underlying computer's configuration, which seems to be what you are looking for.
Both functions return a "timestamp", which is a number representing an amount of seconds elapsed since some earlier date. Furthermore, they are UNIX timestamps. UNIX is an old operating system that laid the foundations for a great deal of things in the world of computer science. For one, it established a standard starting date and time for timestamps, being the 1st of january 1970, at midnight.
As indicated by Kiriot, tick() and os.time() only return timestamps, which aren't exactly human-readable. If you wish to display time in HH:MM:SS format, you may do it like so:
local function formatTime(t)
local t = t or tick()
local hours = math.floor(t / 3600) % 24
local mins = math.floor(t / 60) % 60
local secs = t % 60
return string.format("d:d:d", hours, mins, secs)
end
This little handy formatTime() function can either accept a timestamp to format as argument, or it can generate one on its own based on the current local time.
As for your second question, the Roblox API is the set of features added to Lua by Roblox. This includes all of its variables, functions, and object classes.
The Roblox Wiki's "API Reference" section is essentially a big documentation of everything added by Roblox. You'll want to use that to know how to use Roblox's features properly:
There's also an official Lua reference manual that serves both as an introductory book of sorts to the language as well as a list all of the features of Lua:
Hope this helped you, have fun coding. :)
5 comments
Doesn't os.time() return the local time aswell though?
Nope. It's Universal Coordinated Time.
Isn't d supposed to be %d
Looks like that's an issue with the website. I indeed write "% 02d", with no spaces.
thanks "Greetings from Argentina" :)