tstring CMainFunction::StringToUTC( tstring cStr)
{
TCHAR rcStr[MAX_PATH] = {0} ;
int nYear, nMonth, nDate, nHour, nMin, nSec;
swscanf_s( cStr.c_str(),_T("%d-%d-%d %d:%d:%d"), &nYear, &nMonth, &nDate, &nHour, &nMin, &nSec );
CTime cTime(nYear, nMonth, nDate, nHour, nMin, nSec);
SYSTEMTIME timeFrom;
cTime.GetAsSystemTime(timeFrom);
SYSTEMTIME tm_ptr = {0};
TIME_ZONE_INFORMATION tz = {0};
tz.Bias = -480;
TzSpecificLocalTimeToSystemTime( &tz, &timeFrom, &tm_ptr);
_sntprintf_s( rcStr, _countof(rcStr), _T("%04d-%02d-%02d %02d:%02d:%02d") ,tm_ptr.wYear, tm_ptr.wMonth, tm_ptr.wDay, tm_ptr.wHour, tm_ptr.wMinute, tm_ptr.wSecond);
return rcStr;
} wstring 转 utc时间
最新推荐文章于 2026-06-22 14:23:18 发布
本文介绍了一个使用C++将本地时间字符串转换为协调世界时(UTC)的示例。通过解析输入的时间字符串,构造CTime对象,并利用Windows API进行时区调整,最终输出转换后的UTC时间。

508

被折叠的 条评论
为什么被折叠?



