1#include <ctime>
2#include <iostream>
3
4int main() {
5 std::time_t t = std::time(0); // get time now
6 std::tm* now = std::localtime(&t);
7 std::cout << (now->tm_year + 1900) << '-'
8 << (now->tm_mon + 1) << '-'
9 << now->tm_mday
10 << "\n";
11}
1#include <string>
2#include <sstream>
3#include <iostream>
4
5time_t t = time(0); // get time now
6struct tm * now = localtime( & t );
7
8ostringstream osTime;
9osTime << (now->tm_year + 1900) <<
10 (now->tm_mon + 1) <<
11 now->tm_mday <<
12 "\n";
13
14cout << osTime.str();