Lua的time相关函数

time函数

– 获取当前的格林尼治时间
os.time()
– 获取当前时间的秒表示 示例:1457412434

os.date()
–当前日期的字符串表示 示例:03/08/16 12:47:14

os.date(“%x”, os.time())
– %x 日期,示例:03/08/16

os.date(“%X”, os.time())
– %X 时间,示例:12:47:14

os.date(“%c”, os.time())
– %c 日期和时间 ,示例:03/08/16 12:47:14

os.clock()
–函数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("cost time: %.2f\n", x2 - x1))

根据当前时间计算当日24点时间:

  local time = (当前时间)
  local date = os.date("*t", time )
  local next_date = {}
  next_date.year = date.year
  next_date.month = date.month
  next_date.day = date.day + 1
  next_date.hour = 0
  next_date.min = 0
  next_date.sec = 0
 当日24点 = os.time(next_date)

你可能感兴趣的:(lua,time)