首先應求的系統的時間,然後加上時區,最後將這個時間轉成本地時間即可。
如
struct tm newtime;
__time64_t long_time;
//獲取系統時間
_time64( &long_time );
//獲取時區(以分爲單位)
TIME_ZONE_INFORMATION timezone;
DWORD dwRes = GetTimeZoneInformation(&timezone);
//獲取標準的格林尼治時間
long_time += (timezone.Bias*60);
//將時間轉城本地時間
_localtime64_s(&newtime ,&long_time );
//對時間進行相關操作
CString strTime;
strTime.Format(L"%2d%2d%2d",newtime.tm_hour,newtime.tm_min, newtime.tm_sec);
strTime.Replace(L" ",L"0");
MessageBox(strTime);