Hello anyone know whats wrong in this code? (im learning)
local date = os.time()
local day2year = 365.242 -- days in a year
local sec2hour = 60 * 60 -- seconds in an hour
local sec2day = sec2hour * 24 -- seconds in a day
local sec2year = sec2day * day2year -- seconds in a year
-- year
print(date // sec2year + 1970) --> 2021.0
-- hour (in UTC)
print(date % sec2day // sec2hour)
-- minutes
print(date % sec2hour // 60)
--seconds
print(date % 60)
Passing "*t" to os.date means “break this into its components as a table”. Technically you don’t need to give it the second argument, it defaults to “now”.
Passing anything other than "*t" means “look for specific substrings in this and replace them with the associated components”. For example:
local now = os.time()
local formatString = "It is %A, %x at %I:%M:%S %p"
print(os.date(formatString, now))