Lua获取系统时间和时间格式化方法及格式化参数
一、系统当前时间对应的时间戳
localntime=os.time print(ntime)
二、格式化时间显示,参考下表
常用于设置header等
ngx.header["Last-Modified:"] =os.date("%a,%d%b%Y%XGMT") ngx.header["Content-Type"] ="text/html;charset=utf-8" ngx.header["Cache-Control"] ="public" ngx.header["Expires"] =os.date("%a,%d%b%Y%XGMT",os.time()+cdnCacheTime)
%a
abbreviatedweekdayname(e.g.,Wed)
%A
fullweekdayname(e.g.,Wednesday)
%b
abbreviatedmonthname(e.g.,Sep)
%B
fullmonthname(e.g.,September)
%c
dateandtime(e.g.,09/16/9823:48:10)
%d
dayofthemonth(16)[01-31]
%H
hour,usinga24-hourclock(23)[00-23]
%I
hour,usinga12-hourclock(11)[01-12]
%M
minute(48)[00-59]
%m
month(09)[01-12]
%p
either"am"or"pm"(pm)
%S
second(10)[00-61]
%w
weekday(3)[0-6=Sunday-Saturday]
%x
date(e.g.,09/16/98)
%X
time(e.g.,23:48:10)
%Y
fullyear(1998)
%y
two-digityear(98)[00-99]
%%
thecharacter'%'