Hi, now ... I'm looking for a way to get a player's local time, either from their computer or mobile phone.
First I thought that I need a "GetService" service. But I don't know
I do not have any example script. Sorry
I need your help please.
How can I learn more about the services? and What is "Roblox API"
I Speak spanish
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. :)
The tick()
and os.time()
functions return the player's unix time when used in a LocalScript
. If you want to get the time in h:m:s format, you will need to convert it from the unix timestamp.
Roblox API is stuff such as workspace
, GetService
, etc. in roblox lua. Basically anything which isn't in normal lua.
GetService()
returns the service you specify. There are many services such as Workspace, Players, ReplicatedStorage and so on. Here is the list of all services, although most of them you probably won't use soon.