信息发布→ 登录 注册 退出

Lua常用时间函数使用实例

发布时间:2026-01-11

点击量:
-- 获取当前的格林尼治时间
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}
--]]

标签:# CPU  # startTime  # T2009_AvtivityTime  # temp  # time  # os  # class  # pre  # brush  # print  # plain  # local  # Lua  # string  # clock  # date  # 加载  # 花去  # 则会  # 格林尼治  # 形如  # lua获取未来某时间点的时间戳解决方案  # 时间函数  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!