lua os.time() 和os.date()

来源:互联网 发布:带牛熊先知软件 编辑:程序博客网 时间:2024/05/18 02:58

返回当前系统的时间

print(os.time()) -- 1505200338print(os.date())-- "Tue Sep 12 07:01:30 2017"print(os.date("%Y-%m-%d %H:%M:S", os.time()))-- "2017-09-12 08:50:36"

执行该程序CPU花去的时钟秒数

local x = os.clock()local s = 0for i=1,100000000 do s = s + i endprint(string.format("elapsed time: %.2f\n", os.clock() - x))-- 1.11 

根据时间格式返回时间戳

print(os.time{year=2017, month=9, day=12, hour=15, min=30, sec=0})-- 1505201400

时间表

temp = os.date("*t", 1505200338)for k,v in pairs(temp) do    print(string.format("%s : %s", k, v))end-- "{year = 1998, month = 9, day = 16, yday = 259, wday = 4,hour = 23, min = 48, sec = 10, isdst = false}"
符号 意义 %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 day of the month (16) [01-31] %H hour, using a 24-hour clock (23) [00-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 (e.g., 09/16/98) %X time (e.g., 23:48:10) %Y full year (1998) %y two-digit year (98) [00-99] %% the character ‘%’
原创粉丝点击