Lua - Get current day?

I do not know where to ask about this, so I thought, why not ask Stackoverflow?

I wonder if I can somehow get the current day with Lua?

Something about os.date (), but I have no idea how to do this. Or maybe os.time ()?

as:

local day = os.time()somethingsomething

And then check

if (day == 'monday') then
print('It is monday')
elseif (day == 'tuesday') then
print('It is tuesday!')
end
+4
source share
2 answers

Why not google it? There is an excellent article here. See http://www.lua.org/pil/22.1.html

Try print(os.date("%A"))to get the day of the week.

To check if you can currently write any of these conditions.

if (os.date("%A") == "Monday") then
  print("It Monday")
end
if (os.date("*t").wday == 1) then
  print("It Monday")
end
+2
source

If you need named days:

local daysoftheweek={"Sunday","Monday","Tuesday","Wednesday","Thrusday","Friday","Saturday"}
local day=daysoftheweek[os.date("*t").wday]
print(day)

os.date("*t").wday, 1 , 2 ..

+2

Source: https://habr.com/ru/post/1532560/


All Articles