tags:

views:

600

answers:

4

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?

+2  A: 

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

Charlie Martin
+2  A: 

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

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

Steve Madsen
A: 

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

lothar
A: 
#include <iostream>
#include <sys/time.h>

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