Answers for "get current date in c++"

C++
1

get current date in c++

#include <ctime>
#include <iostream>

int main() {
    std::time_t t = std::time(0);   // get time now
    std::tm* now = std::localtime(&t);
    std::cout << (now->tm_year + 1900) << '-' 
         << (now->tm_mon + 1) << '-'
         <<  now->tm_mday
         << "\n";
}
Posted by: Guest on April-24-2021
0

c++ get system date

#include <string>
#include <sstream>
#include <iostream>

time_t t = time(0);   // get time now
struct tm * now = localtime( & t );

ostringstream osTime;
osTime << (now->tm_year + 1900) <<
   (now->tm_mon + 1) <<
   now->tm_mday <<
   "\n";

cout << osTime.str();
Posted by: Guest on April-13-2021

Browse Popular Code Answers by Language