lua 中操作系统库

time 和 date 两个函数在lua中实现所有的时钟查询功能。

函数time在没有参数时返回当前时钟的数值。(在许多操作系统中,该数值是距离某个特定时间的秒数)。

date是time的一种“反函数”,将数值转换为年月日时分秒

使用格式字符"*t",创建一个时间表。

temp = os.date("*t", 906000490)

返回的结果为:

{year=1998, month=9, day=16, yday=259,  wday=4, hour=23, min=48, sec=10, isdst=false}

还可以按照一定的格式输出,主要使用的格式如下:

%a          abbreviated weekday name(eg. Wed)   缩写的星期几

%A          full weekday name(eg. Wednesday)  全写的星期几

%b          abrreivated month name(eg, Sep)  缩写的月份名

%B          full month name(eg, September) 全写的月份名

%c           date and time(eg, 09/16/98 23:48:10)

%d          day of the month(16)[0-31]

%H          hour, using a 24-hour clock (23)[0-23]

%I           hour, using a 12-hour clock(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(eg, 09/16/98)

%X           time(eg, 23:48:10)

%Y           full year(1998)

%y           two-digit year(98)[00-99]

%%          the character '%'

原文地址:https://www.cnblogs.com/rohens-hbg/p/5345018.html