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

How to display a user's time?

I want to display a user's pc time on a gui in my game, I'm not sure whether I use tick or os.time or whatever one of those, I just need to know how and to display it in the format hour:minute (10:25 e.g).

1 answer

✓ Accepted answer

You would use os.date

os.date() returns a table composed of:

year

month

wday (week day)

yday (year day)

day (day of the month)

hour

min

sec

isdst (A boolean describing if daylight savings time is currently active.)

To get the hour and minute from os.date() you would do the following:

os.date("*t")["hour"] -- *t gets computer's local time, you can substitute it with !*t for UTC time

os.date("*t")["min"]

tick() get the seconds passed from January 1st, 1970 on your computer's time.

os.time() is a table like os.date() but uses UTC time instead of the local computer's time.

Hope this helps.

If you need more info on os.date() go to: http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#os.date

3 comments

0

tick() also has milliseconds in it.

0

Why use a string key for os.date? Doesn't it return a static dictionary? As in, you could just do os.date("*t").min; because the min timer would never return nil (or atleast, it shouldn't..)

0

Do remember that if you would like the user's time, use this on a LocalScript, not on a server script. or else it will use server's local time.

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