Using ctime() to get the current time
#include <time.h>
#include <iostream>
using namespace std;
int main()
{
time_t currentTime;
// get and print the current time
time (¤tTime); // fill now with the current time
cout << "It is now " << ctime(¤tTime) << endl;
struct tm * ptm= localtime(¤tTime);
cout << "Today is " << ((ptm->tm_mon)+1) << "/";
cout << ptm->tm_mday << "/";
cout << ptm->tm_year << endl;
cout << "\nDone.";
return 0;
}
Related examples in the same category