Lua中的日期格式toUTCString

标签 date lua utc luajit

我对 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 function strftime.

基于此和一点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/

相关文章:

lua - nginx proxy_pass 基于请求方法是 POST、PUT 还是 DELETE

lua - Lua中我不明白的变量声明

C# - DateTime.FromFileTimeUtc 到 DateTime.FromFileTime

MySql - 选择UTC格式的时间戳列

java - 使用 Calender 或 java 中的任何类查找上个月名称

c# - 将两位数年份转换为四位数年份

android - 获取离当前时间最近的日期

date - 如何编写表达式将 ssrs 中的 yyyymm 转换为 mm-yyyy?

lua - 如何在错误消息中显示正确的函数名称?

PHP UTC 时区