鉴于日期和时间,你如何获得大纪元时间?

时间:2009-05-20 21:25:18

标签: c++ epoch

我有

int year, month, day, hour, min, sec

如何在C ++中获取纪元时间?

我很难使用Boost,任何示例或替代方法来解决它?

4 个答案:

答案 0 :(得分:4)

使用您的值填写struct tm,然后调用std::mktime()

我假设“获取纪元时间”是指自纪元以来的秒数,即Unix time_t。

答案 1 :(得分:2)

你太复杂了。看看time functions in the standard libraries

答案 2 :(得分:1)

如果我能正确理解您的问题,那么boost example应该按照您的要求行事。

答案 3 :(得分:1)

#include <iostream>
#include <sys/time.h>

int main ()
{
  unsigned long int seconds = time(NULL);
  std::cout << seconds << std::endl;
  return 0;
}
相关问题