将字符串转换为时间戳
Convert string to timestamp
如何将此字符串转换为 Lua 中的时间戳?
2017-02-04T15:12:02.866Z
我浏览了 SO 的例子,它们都是 return 无,无,无...
例如,这不起作用:
local pattern = "(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)"
local timeToConvert = "2017-02-04T15:12:02.866Z"
local runyear, runmonth, runday, runhour, runminute, runseconds = timeToConvert:match(pattern)
看起来您只是在模式中缺少 'T':
local pattern = "(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)"
看看 luatz 的 parse.rfc_3339
does it: https://github.com/daurnimator/luatz/blob/eabec5f434225aa68aa33565d8cf5055f287662e/luatz/parse.lua#L8
如何将此字符串转换为 Lua 中的时间戳?
2017-02-04T15:12:02.866Z
我浏览了 SO 的例子,它们都是 return 无,无,无...
例如,这不起作用:
local pattern = "(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)"
local timeToConvert = "2017-02-04T15:12:02.866Z"
local runyear, runmonth, runday, runhour, runminute, runseconds = timeToConvert:match(pattern)
看起来您只是在模式中缺少 'T':
local pattern = "(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)"
看看 luatz 的 parse.rfc_3339
does it: https://github.com/daurnimator/luatz/blob/eabec5f434225aa68aa33565d8cf5055f287662e/luatz/parse.lua#L8