在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
原文引自:https://www.ogeek.net/article/64466.htm -- 获取当前的格林尼治时间 print(os.time()) -- 获取当前时间的字符串表示,形如:11/28/08 10:28:37 print(os.date()) -- 获取当前日期的字符串表示,形如:11/28/08 print(os.date("%x", os.time())) -- 获取当前时间的字符串表示,形如:10:28:37 print(os.date("%X", os.time())) -- 获取当前时间的字符串表示,形如:10/10/13 10:28:37 print(os.date("%c", os.time())) -- 获取当前时间的字符串表示,形如:2013-10-10 10:28:37 print(os.date("%Y-%m-%d %H:%M:%S", os.time())) --函数os.clock返回执行该程序CPU花去的时钟秒数 local x1 = os.clock() local s = 0 for i = 1, 10000000 do s = s + i end local x2 = os.clock() print(string.format("elapsed time: %.2f\n", x2 - x1)) local T2009_StartTime = { year=2013, month=2, day=9, hour=0, min=0, sec=0 } local T2009_EndTime = { year=2013, month=2, day=17, hour=23, min=59, sec=59 } T2009_AvtivityTime = { startTime = os.time(T2009_StartTime), endTime = os.time(T2009_EndTime) } print('加载礼包活动成功,活动时间:' .. os.date('%c', T2009_AvtivityTime.startTime) .. '~' .. os.date('%c', T2009_AvtivityTime.endTime)) temp = os.date("*t", os.time()) print(temp) --[[则会产生表 {year = 1998, month = 9, day = 16, yday = 259, wday = 4, hour = 23, min = 48, sec = 10, isdst = false} --]] 字符串与时间戳转化时间戳转成格式化字符串local timestamp = 1561636137; local strDate = os.date("%Y/%m/%d %H:%M:%S", timestamp) print("strDate = ", strDate); 字符串转化成时间戳分离 local strDate = "2019/06/27 19:48:57" local _, _, y, m, d, hour, min, sec = string.find(strDate, "(%d+)/(%d+)/(%d+)%s*(%d+):(%d+):(%d+)"); --分离字符串 前两个不知道是什么? print(y, m, d, hour, min, sec); 转化 --转化为时间戳 local timestamp = os.time({year=y, month = m, day = d, hour = hour, min = min, sec = sec}); print("timestamp = ", timestamp);
|
请发表评论