c++获取当前日期(秒&毫秒)

 time_t t1 = time(0);
 char ch1[64];
 strftime(ch1, sizeof(ch1), "%Y", localtime(&t1)); //年-月-日 时-分-秒
 std::string showText1 = ch1;

微秒

 #include //必须包此头文件 :时间需要
SYSTEMTIME t;
GetLocalTime(&t);
std::cout << t.wYear << "" << t.wMonth << "" << t.wDay << "_" //就是毫秒数
            << t.wHour << "" << t.wMinute << "" << t.wSecond << "" << t.wMilliseconds << std::endl;
std::string timenow = std::to_string(t.wYear)
            + std::to_string(t.wMonth)
            + std::to_string(t.wDay)
            + "_"
            + std::to_string(t.wHour)
            + std::to_string(t.wMinute)
            + std::to_string(t.wSecond)
            + std::to_string(t.wMilliseconds);
std::cout << timenow << std::endl;

你可能感兴趣的:(c++获取当前日期(秒&毫秒))