Like @ 0A0D , but you cannot change asctime , you can use strftime to format the data contained in your time_t :
string get_current_time() { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); char output[30]; strftime(output, 30, "%Y %m-%d %H-%M-%S %a", timeinfo); return string(output); }
(I also threw a copy on IdeOne here .)
source share