//获取系统时间
vector<string> PinDetect::get_current_time()
{
/*能精确到毫秒*/
/*
#include <windows.h>
#include <iostream>
*/
SYSTEMTIME st = { 0 };
GetLocalTime(&st); //获取当前时间 可精确到ms
char tmpbuff[16];
/*年*/
sprintf(tmpbuff, "%d", st.wYear);
std::string year = tmpbuff;
/*月*/
sprintf(tmpbuff, "%d", st.wMonth);
std::string month = tmpbuff;
/*日*/
sprintf(tmpbuff, "%d", st.wDay);
std::string day = tmpbuff;
/*时*/
sprintf(tmpbuff, "%d", st.wHour);
std::string hour = tmpbuff;
/*分*/
sprintf(tmpbuff, "%d", st.wMinute);
std::string minute = tmpbuff;
/*秒*/
sprintf(tmpbuff, "%d", st.wSecond);
std::string second = tmpbuff;
/*毫秒*/
sprintf(tmpbuff, "%d", st.wMilliseconds);
std::string millisecond = tmpbuff;
std::vector<string>current_time = {};
current_time.push_back(year + month + day);
current_time.push_back(hour + minute + second);
current_time.push_back(year + month + day + hour + minute + second);
current_time.push_back(year + "_" + month + "_" + day + "_" + hour + "_" + minute + "_" + second + "_" + millisecond);
return current_time;
}
C++获取系统时间,精确到毫秒
于 2024-06-25 13:11:18 首次发布