1. 日期转秒:
datestr="2021-12-30 03:27"
pattern="(%d+)-(%d+)-(%d+) (%d+):(%d+)"
year,month,day,hour,min=datestr:match(pattern)
print(day, month, year, hour, min)
print(os.time({day=day, month=month, year=year, hour=hour, min=min, sec=0}))
> 30 12 2021 03 27
> 1640806020
---指定日期转为秒
print(os.time({day=17, month=8, year=2018, hour=0, minute=0, second=0}))
1534435200
2. 秒数转日期:
print(os.date("%Y-%m-%d %H:%M:%S",1479892620))
2016-11-23 17:17:00
os.time() 不传参的话返回当前时间转化成秒数的结果
print(os.time())
1640807175
print(os.date("%Y-%m-%d %H:%M:%S", os.time()))
2021-12-30 03:45:40
3. 时间戳转换:https://tool.lu/timestamp/