#include <windows.h> #include <chrono> #include <ctime> #include <iostream> using namespace std; LONGLONG GetCurTime() { return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); } int main() { INT64 milli = GetCurTime() + (INT64)8 * 60 * 60 * 1000;//此处转化为东八区北京时间,如果是其它时区需要按需求修改 auto mTime = std::chrono::milliseconds(milli); auto tp = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>(mTime); auto tt = std::chrono::system_clock::to_time_t(tp); std::tm* now = std::gmtime(&tt); printf("%4d年%02d月%02d日 %02d:%02d:%02d\n", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); //struct tm结构和struct SYSTEMTIME结构的年和月的取值范围是不一样的 : //tm.tm_mon = systemtime.wMonth - 1 //tm.tm_year = systemtime.wYear - 1900 SYSTEMTIME st; st.wYear = now->tm_year + 1900; st.wMonth = now->tm_mon + 1; st.wDayOfWeek = now->tm_wday; st.wDay = now->tm_mday; st.wHour = now->tm_hour; st.wMinute = now->tm_min; st.wSecond = now->tm_sec; st.wMilliseconds = 0; while (1); return 0; }