#include <chrono>
#include <ctime>
#include <iostream>
int main() {
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
struct tm * ptminfo = localtime(&tt);
printf("current: %02d-%02d-%02d %02d:%02d:%02d\n",
ptminfo->tm_year + 1900, ptminfo->tm_mon + 1, ptminfo->tm_mday,
ptminfo->tm_hour, ptminfo->tm_min, ptminfo->tm_sec);
char date[60] = { 0 };
sprintf(date, "%02d-%02d-%02d %02d:%02d:%02d", ptminfo->tm_year + 1900, ptminfo->tm_mon + 1, ptminfo->tm_mday, ptminfo->tm_hour, ptminfo->tm_min, ptminfo->tm_sec);
//sprintf(date, "%02d%02d%02d", ptminfo->tm_year + 1900, ptminfo->tm_mon + 1, ptminfo->tm_mday);
std::cout << std::string(date) << std::endl;
std::cin.get();
}
C++ std::chrono获取当前系统时间
最新推荐文章于 2024-08-23 16:09:48 发布