Use system time : Time « Development « C++






Use system time

Use system time
 

#include <iostream>
#include <ctime>
using namespace std;

class TimeDate {
  time_t systime;
public:
  TimeDate(time_t t); // constructor
  void show();
};

TimeDate::TimeDate(time_t t)
{
  systime = t;
}

void TimeDate::show()
{
  cout << ctime(&systime);
}

int main()
{
  time_t x;

  x = time(NULL);

  TimeDate ob(x);

  ob.show();

  return 0;
}

           
         
  








Related examples in the same category

1.Overload date() for time_t.Overload date() for time_t.
2.Using ctime() to get the current time
3.Output a time value with ctime