我有
int year, month, day, hour, min, sec
如何在C ++中获取纪元时间?
我很难使用Boost,任何示例或替代方法来解决它?
答案 0 :(得分:4)
使用您的值填写struct tm,然后调用std::mktime()
。
我假设“获取纪元时间”是指自纪元以来的秒数,即Unix time_t。
答案 1 :(得分:2)
答案 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;
}