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; }