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

How to use os.time() (or something else?) to get the hours, minutes, seconds time format?

First of all, I apologize sincerely for not writing a code. I would like to write a code, but I just want to print the hours, minutes, and seconds format in the console. I tried print(os.time()), expecting errors, and of course, I got errors. Can anyone just give me a redirect, or explain to me how to use this to get and print the hours, minutes, and seconds time format with os.time()? That would be very helpful.

1 answer

✓ Accepted answer

I would suggest using another function available in roblox os.date. This takes in a weird string ... either "!*t" (corresponds to not using daylight savings time) or "*t" (corresponds to using daylight savings time), and the unix timestamp provided by os.time() (this is a count of the number of seconds elapsed since some date in 1970, usually only machines parse this).

What you get back is a table containing components of the current date (including hours, minutes, seconds). For example.

mydatetable = os.date("*t", os.time())
for key, value in pairs(mydatetable) do
    print(key .. " , " .. tostring(value))
end

The above code generated the following output when I ran it a second ago (on an online lua interpreter unfortunately I don't have access to a roblox workstation atm).

min , 53
wday , 3
yday , 127
sec , 40
isdst , true
month , 5
year , 2019
day , 7
hour , 1

So to access hours, mins or seconds you would specifically use mydatetable['hour'], mydatetable['min'], mydatetable['sec'].

Cheers.

2 comments

0

Also keep in mind the date hours, minutes, and seconds will be for the UTC timezone. Not the timezone you are likely in.

0

Okay, thanks

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