gpt4 book ai didi

c - 如何将日期时间转换为 c 中的 unix 时间戳?

转载 作者:太空狗 更新时间:2023-10-29 16:27:36 25 4
gpt4 key购买 nike

场景是:我使用 libexif 获取格式为“YYYY-MM-DD HH:MM:SS”的日期时间。为了尽量减少节省成本,我想将日期时间转换为 unix 时间戳或类似的东西,只需 64 位或 32 位。 c 有什么明确的方法吗?

最佳答案

您可以尝试 strptime 的组合和 mktime

struct tm tm;
time_t epoch;
if ( strptime(timestamp, "%Y-%m-%d %H:%M:%S", &tm) != NULL )
epoch = mktime(&tm);
else
// badness

关于c - 如何将日期时间转换为 c 中的 unix 时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1002542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com