Getting previous day's date in Lua

2020-07-23 08:23发布

问题:

Can anyone kindly enlighten me on how to get previous day's date in 'YYYY-MM-DD' format using Lua?

I.E., a snippet that will return the date of the previous day from the day during which it is run.

回答1:

Try

print(os.date("%Y-%m-%d",os.time()-24*60*60))

Strictly speaking this is only guaranteed to work on a POSIX system, but it probably works in most systems.



回答2:

There is a library LuaDate which can be very helpful for Date Manipulations http://luaforge.net/projects/date/

It is very easy to use, since it is documented well!



标签: lua