本文主要是介绍lua data time,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
local getTime = os.date(“%c”);
其中的%c可以是以下的一种:(注意大小写)
%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 ‘%’
如获取当前年月日时分秒:local date=os.date(“%Y-%m-%d %H:%M:%S”);
os.time()
获取当前秒-标准时间秒
print(“data:”, os.date()," time:", os.time())
local time = os.time({year =2016, month = 11, day =23, hour =17, min =17, sec = 00})
print(time)
回当前系统的时间
print(os.time())
– 1505200338
print(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”
1
2
3
4
5
6
执行该程序CPU花去的时钟秒数
local x = os.clock()
local s = 0
for i=1,100000000 do s = s + i end
print(string.format(“elapsed time: %.2f\n”, os.clock() - x))
根据时间格式返回时间戳
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}”
这篇关于lua data time的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!