- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 Lua (Luajit) 中的日期格式有疑问。例如,我需要获取 UTC 字符串,就像我在 JavaScript 中那样:
var date = new Date()
console.log(date.toUTCString()) // "Fri, 06 Dec 2013 14:05:28 GMT"
不幸的是,在 Lua 中我找不到以这种方式格式化日期的可能性:
print(os.date()) -- Fri Dec 6 16:06:43 2013
最佳答案
来自 Lua manual :
If format starts with '
!
', then the date is formatted in Coordinated Universal Time. [...]If format is not "
*t
", then date returns the date as a string, formatted according to the same rules as the ANSI C functionstrftime
.
基于此和一点documentation referencing ,构造类似于 JavaScript 的 toUTCString
格式的格式字符串非常简单。
> =os.date('!%a, %d %b %Y %H:%M:%S GMT')
Fri, 06 Dec 2013 14:27:34 GMT
关于Lua中的日期格式toUTCString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20425867/
我从网络服务返回一个 JSON 字符串。我也在 W3C 学校网站上为我们的本地计算机测试了同样的东西。我通过 Javascript 从 UTC 字符串返回服务和 W3C 站点的时间提前了 2 小时。有
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我在下个月的随机日期创建随机时间,这样 var time = new Date(now.getFullYear(), now.getMonth() + 1,
我正在将数据保存在 MongoDB 中服务器来自 Node.js应用程序(使用 Mongoose )。 考虑以下代码: var mongoose = require('mongoose'); var
我需要得到如下格式 2015 年 8 月 19 日 04:22:36 GMT 我有以下代码 var dt = '2015-08-19 04:22:36'; alert(new Date(dt).toU
如何在 Javascript 上将 python 结果作为 new Date().toUTCString() 获取? 在我制作的 Javascript 上: new Date().toUTCStrin
在我的 React 应用程序中,日期组件的 .toUTCString() 将其时区显示为“GMT”。这是错误的——格林威治标准时间与 UTC 不同:GMT 是时区,UTC 是时间标准,而且该方法字面上
我知道如何将 new Date() 更改为 UTC 时间new Date().toUTCString()但我想更进一步,获取 UTC 时间,然后将其更改为 1970 年 1 月 1 日以来的毫秒数。
我是一名优秀的程序员,十分优秀!