| 语法: |
os.date(format [, time]]) |
|
| 参数 |
类型 |
说明 |
| format |
字符串类型 |
时间格式化符 |
| time |
整数类型 |
时间戳,默认不写时取当下时间戳 |
| return |
字符串类型
|
时间戳/指定table参数时间戳 |
| 格式化符 |
说明 |
| %a |
abbreviated weekday name (e.g., Wed) |
| %A |
full weekday name (e.g., Wednesday) |
| %b |
abbreviated month name (e.g., Sep) |
| %B |
full month name (e.g., September) |
| %c |
date and time (e.g., 09/16/98 23:48:10) |
| %d |
一个月里的几号[01–31] |
| %H |
24小时[00–23] |
| %I |
12小时[01–12] |
| %j |
一年中的第几天[001–366] |
| %M |
分[00–59] |
| %m |
月份[01–12] |
| %p |
am(上午),pm(下午) |
| %S |
秒[00–60] |
| %w |
星期几[0–6 = 星期天–星期六] |
| %x |
date (e.g., 09/16/98) |
| %X |
time (e.g., 23:48:10) |
| %y |
two-digit year (98) [00–99] |
| %Y |
年(1998) |
| %% |
the character ‘%’ |
local now = os.date("%Y-%m-%d %H:%M:%S")local secs = os.time()local year = string.sub(now,1,4)local month = string.sub(now,6,7)local day = string.sub(now,9,10)local hour = string.sub(now,12,13)local minute = string.sub(now,15,16)local second = string.sub(now,18,19)--获取7天前的时间ta = {year=year,month=month,day=day-7,hour=hour,min=minute,sec=second}--2018-05-02 09:50:57local t = os.date("%Y-%m-%d %H:%M:%S", os.time(ta))--获取本年2月份的天数--3月份开头减去1天就是2月份的最后一天ta = {year=year,month=3,day=0,}--28local days = os.date("%d", os.time(ta))