如何将datetime转换为unix时间戳? [英] how to convert datetime to unix timestamp in c?
本文介绍了如何将datetime转换为unix时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
情况是:我使用libexif获取格式为YYYY-MM-DD HH:MM:SS的datetime。为了最小化节省成本,我想将datetime转换为unix时间戳或类似的,只能花费64bit或32bit。有没有明确的方法与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?
推荐答案
struct tm tm;
time_t epoch;
if ( strptime(timestamp, "%Y-%m-%d %H:%M:%S", &tm) != NULL )
epoch = mktime(&tm);
else
// badness
这篇关于如何将datetime转换为unix时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文