>>Is there a way to do that?
There sure is :-)
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t current;
current = time(0);
if (current != static_cast<time_t>(-1))
{
cout<< ctime(¤t) <<flush;
}
}
You can also use the tm struct and get more control over the content itself :-)
Code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t current;
struct tm *date;
char datestr[1024];
const char fmt[] = "%A %B %d, %y -- %I:%M:%S %p";
current = time(0);
date = localtime(¤t);
if (strftime(datestr, sizeof datestr, fmt, date) != 0)
{
cout<< datestr <<endl;
}
}