这是一个非常古老的问题,并且有与此类似的主题 here和 here等等。我有:
- 年份,例如2014,
月如10,
- ...
- seconds like 23.
使用这些整数 我想获得unix 时间(自1970. 01. 01. 以来的秒数)。但最后我又只想要一个整数。我该怎么做?
我只能使用 STL 和 QT(不能使用 Boost)。我知道有 QDateTime 可以解决这个问题,但我仍然不知道如何解决。
编辑 1: 我试过这个,但似乎出了点问题:
const WCCIL::QDate dd(/*fill it*/);
const WCCIL::QTime tt(/*fill it*/);
WCCIL::QDateTime ddtt( dd, tt); // error, no constructor
ddtt.toUTC();
最佳答案
您发布的第一个链接 ( C++ How can I convert a date in year-month-day format to a unix epoch format? ) 包含您想要的答案。您需要将 tm
结构与 mktime()
一起使用。查看mktime()
手册页以获取更多信息。
关于c++ - 在 CPP 中将时间转换为 unix 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26180653/