Given the date and time, how do you get the time in the era?

I have

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

      

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

I am having a hard time understanding using Boost, any examples or alternative ways to do this?

0


a source to share


4 answers


Fill the tm structure with your values, then call std::mktime()

.



I assume that "get epoch time" means the number of seconds since epoch, ie Unix time_t.

+4


a source


You are making it too hard. Take a look at the time functions in standard libraries .



+2


a source


This boost example should do what you are asking if I understood your problem correctly.

+1


a source


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

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

      

+1


a source







All Articles