【问题标题】:How can I get the current UTC time in a Lua script?如何在 Lua 脚本中获取当前的 UTC 时间?
【发布时间】:2013-09-29 17:38:51
【问题描述】:

如何使用 Lua 脚本获取当前 UTC 时间并将其转换为人类可读的文本?

【问题讨论】:

    标签: lua timezone utc


    【解决方案1】:

    试试os.date("!%c")。这里! 表示UTC,%c 表示标准格式的完整日期。有关其他选项,请参阅http://www.lua.org/manual/5.2/manual.html#pdf-os.date

    curTime = os.time(); print("os.date(): "..os.date('%Y-%m-%d-%H:%M:%S', curTime));  
    print("os.date(!): "..os.date('!%Y-%m-%d-%H:%M:%S GMT', curTime))
    

    【讨论】:

    • 感谢您的回答,这里有一些扩展使用!的示例代码:cutTime = os.time(); print("os.date(): "..os.date('%Y-%m-%d-%H:%M:%S', curTime)); print("os.date(!): "..os.date('!%Y-%m-%d-%H:%M:%S GMT', curTime))
    • @TzunghsingDavidWong - 请编辑答案以将您的评论纳入其中。评论被多次删除。
    猜你喜欢
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    • 2012-07-24
    • 2020-06-04
    • 2017-10-07
    • 1970-01-01
    相关资源
    最近更新 更多