I have
int year, month, day, hour, min, sec
How can I get the epoch time in C++?
如何在C ++中获得纪元时间?
I am having difficulty figuring it out using Boost, any examples or alternative ways to do it?
我很难使用Boost来解决它,任何示例或替代方法来做到这一点?
4 个解决方案
#1
Fill in a struct tm with your values, then call std::mktime()
.
使用您的值填写struct tm,然后调用std :: mktime()。
I'm assuming by "get the epoch time" you mean the number of seconds since the epoch, i.e. Unix time_t.
我假设“获取纪元时间”是指自纪元以来的秒数,即Unix time_t。
#2
You're making it too complicated. Have a look at the time functions in the standard libraries.
你太复杂了。看看标准库中的时间函数。
#3
This boost example should do what you ask for if I did understand your problem correctly.
如果我能正确理解您的问题,这个提升示例应该按照您的要求执行。
#4
#include <iostream>
#include <sys/time.h>
int main ()
{
unsigned long int seconds = time(NULL);
std::cout << seconds << std::endl;
return 0;
}
#1
Fill in a struct tm with your values, then call std::mktime()
.
使用您的值填写struct tm,然后调用std :: mktime()。
I'm assuming by "get the epoch time" you mean the number of seconds since the epoch, i.e. Unix time_t.
我假设“获取纪元时间”是指自纪元以来的秒数,即Unix time_t。
#2
You're making it too complicated. Have a look at the time functions in the standard libraries.
你太复杂了。看看标准库中的时间函数。
#3
This boost example should do what you ask for if I did understand your problem correctly.
如果我能正确理解您的问题,这个提升示例应该按照您的要求执行。
#4
#include <iostream>
#include <sys/time.h>
int main ()
{
unsigned long int seconds = time(NULL);
std::cout << seconds << std::endl;
return 0;
}