当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Given date and time, how do you get the Epoch time?

问题描述:

I have

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

How can I get the epoch time in C++?

I am having difficulty figuring it out using Boost, any examples or alternative ways to do it?

网友答案:

Fill in a struct tm with your values, then call std::mktime().

I'm assuming by "get the epoch time" you mean the number of seconds since the epoch, i.e. Unix time_t.

网友答案:

You're making it too complicated. Have a look at the time functions in the standard libraries.

网友答案:

This boost example should do what you ask for if I did understand your problem correctly.

网友答案:
#include <iostream>
#include <sys/time.h>

int main ()
{
  unsigned long int seconds = time(NULL);
  std::cout << seconds << std::endl;
  return 0;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: