12345678910
#include <ctime> #include <iostream> const time_t ctt = time(0); int main() { std::cout << asctime(localtime(&ctt)) << std::endl; return 0; }
1234567
std::string now( const char* format = "%c" ) { std::time_t t = std::time(0) ; char cstr[128] ; std::strftime( cstr, sizeof(cstr), format, std::localtime(&t) ) ; return cstr ; }
123
std::cout << now() << '\n' ; file << "some log message - posted at:" << now( "%I:%M:%S %p %Z" ) << '\n' ; // etc.