使用Lua将0秒的格式设置为00:00:00 [英] Using Lua to format 0 seconds as 00:00:00

查看:164
本文介绍了使用Lua将0秒的格式设置为00:00:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将持续时间(以秒为单位)格式化为时间,并且得到的结果表明我应该考虑某个地方的时代.我希望os.date("%X", 0)产生"00:00:00",但它返回"20:00:00"以及日期值"12/31/69"(不过我不需要日历日期)

I'm trying to format a duration (in seconds) as a time and I'm getting results indicating that I'm supposed to account for an epoch somewhere. I expected os.date("%X", 0) to produce "00:00:00" but it is returning "20:00:00" as well as a date value of "12/31/69" (I don't need a calendar date though).

是否存在获取持续时间字符串的标准方法,该持续时间字符串会导致0秒产生代表总计零秒的时钟?我似乎无法在任何尝试做的事情中找到示例.

Is there a standard way of getting a time duration string that causes 0 seconds to produce a clock representing a total of zero seconds? I can't seem to find an example anywhere of what I'm trying to do.

谢谢

推荐答案

在大多数系统(即POSIX)中,os.date("%X",0)为您提供纪元时间,即00:00:00(协调世界时,UTC) ),1970年1月1日. 之所以得到20:00:00,是因为您所在的时区不同.

In most systems (ie, POSIX), os.date("%X",0) gives you the time of the epoch, which is 00:00:00 (Coordinated Universal Time, UTC), 1 January 1970. You get 20:00:00 because you're in a different time zone.

要强制使用UTC而不是您的时区,请从!开始格式. 手册中提到.

To force UTC instead of your time zone, start the format with !. This is mentioned in the manual.

因此,根据需要使用os.date("!%X",0)获取00:00:00.它可以在一天之内(86400)以任何秒数运行.例如,os.date("!%X",70)给出00:01:10:1分10秒.

So, use os.date("!%X",0) to get 00:00:00 as desired. It'll work with any number of seconds less than a day (86400). For instance, os.date("!%X",70) gives 00:01:10: 1 minute and 10 seconds.

这篇关于使用Lua将0秒的格式设置为00:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆