首页 > 解决方案 > 如何在 Lua 中 os.date() 生成的日期中添加天数

问题描述

模块中调用date()了一个lua函数。os调用os.date()将以以下格式给出当前日期和时间:Tue Aug 10 13:04:17 2021.

这样做:os.date("%x")给我们以下内容:08/10/21.

是否可以操纵日期函数将天数添加到当前返回的日期时间/日期?类似于当您尝试使用.setDate()mutator 将日期添加到 JavaScript 日期时发生的情况。我已经看过How to add days in given datetime in Lua,但这不是我想要实现的。

提前感谢您的帮助。

标签: lua

解决方案


使用os.time和计算秒数:

t=os.time()
print(os.date("%c",t))
d=12
t=t+d*24*60*60
print(os.date("%c",t))

推荐阅读