【发布时间】:2020-04-20 19:42:44
【问题描述】:
我有一个类似于 1587405820 -0600 的 UNIX 样式时间戳,我想将其转换为 ISO 样式格式,例如 YYYY-MM-DDTHH:MM:SSZ
CMake 在https://cmake.org/cmake/help/v3.12/command/string.html#timestamp 有一个string(TIMESTAMP ...) 命令,但这只会让我获得格式化字符串中的当前 时间,这对我的应用程序不起作用。我需要能够将现有时间转换为 ISO 格式。
有没有办法做到这一点?
更新
根据@squareskittles 的回答,这就是我最终得到的这个测试是正确的:
# Check that we get the current timestamp
string(TIMESTAMP TIME_T UTC)
message(STATUS ">>> T1: ${TIME_T}")
# Get the ISO string from our specific timestamp
set(ENV{SOURCE_DATE_EPOCH} 1587405820)
string(TIMESTAMP TIME_T UTC)
unset(ENV{SOURCE_DATE_EPOCH})
message(STATUS ">>> T2: ${TIME_T}")
# Check that we get the current timestamp again correctly
string(TIMESTAMP TIME_T UTC)
message(STATUS ">>> T3: ${TIME_T}")
这给了我这个输出:
-- >>> T1: 2020-04-22T15:08:13Z
-- >>> T2: 2020-04-20T18:03:40Z
-- >>> T3: 2020-04-22T15:08:13Z
【问题讨论】:
标签: cmake unix-timestamp