最近要使用CString转UCT的实现网上找了很多都没找到,所以就自己写了一个
希望对同样也有需要的朋友有帮助
</pre><pre name="code" class="cpp">#include# WinBase.h //头文件
CString CStringToUTC( CString cStr)
{
CString rcStr;
int nYear, nMonth, nDate, nHour, nMin, nSec;
swscanf_s(cStr.GetBuffer(cStr.GetLength()),_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);
rcStr.Format(_T("%d-%d-%d %d:%d:%d") ,tm_ptr.wYear, tm_ptr.wMonth, tm_ptr.wDay, tm_ptr.wHour, tm_ptr.wMinute, tm_ptr.wSecond);
return rcStr;
}
TzSpecificLocalTimeToSystemTime函数的具体含义可以查询MSDN
本文提供了一种将CString转换为UCT的有效实现方式。通过详细解释代码逻辑,包括日期时间解析、本地时间到UCT时间的转换等步骤,为需要进行此类转换的开发者提供了参考。

2万+

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



