c - 如何将日期时间转换为c中的unix时间戳? [英] how to convert datetime to unix timestamp in c?
本文介绍了c - 如何将日期时间转换为c中的unix时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
场景是:我使用 libexif 以YYYY-MM-DD HH:MM:SS"格式获取日期时间.为了最大限度地减少节省成本,我想将日期时间转换为仅花费 64 位或 32 位的 unix 时间戳或类似内容.c 有什么明确的方法吗?
the scenario is: I get datetime in format "YYYY-MM-DD HH:MM:SS" with libexif. To minimize the saving cost, I wanna convert the datetime to unix timestamp or alike which only cost 64bit or 32bit. Is there any explicit way with c?
推荐答案
You could try a combination of strptime and 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时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文