Hi all,
I'm learning C++ from a textbook and got stumped by an exercise asking for a constructor capable of using the current time from the time and localtime functions in <ctime> in a class called Time.
So far I've been playing around and formulating a plan to find the answer, here's what I have so far:
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t t;
t = time( NULL );
cout << "Number of seconds passed since Jan. 1, 1970: " << t << endl;
cout << "Number of minutes passed since Jan. 1, 1970: " << t / 60 << endl;
cout << "Number of hours passed since Jan. 1, 1970: " << ( t / 60 ) / 60 << endl;
cout << "Number of days passed since Jan. 1, 1970: " << ( ( t / 60 ) / 60 ) / 24 << endl;
cout << "Number of years passed since Jan. 1, 1970: " << ( ( ( t / 60 ) / 60 ) / 24 ) / 365 << endl;
} // end main
That's relatively easy, but how on Earth do I work out the months?