C++11获取时间

    科技2023-10-08  86

    C++11获取时间

    const std::string GetCurrentSystemTime() { auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); struct tm* ptm = localtime(&t); char date[60] = { 0 }; sprintf(date, "%d-%02d-%02d %02d:%02d:%02d", (int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday, (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec); return move(std::string(date)); } int main(int argc, char* argv[]) { std::string strCurTime = GetCurrentSystemTime(); printf("当前时间: %s\n", strCurTime.c_str()); }
    Processed: 0.012, SQL: 8