如何用win32 API转换时区?
发布时间:2020-12-14 01:58:03 所属栏目:Windows 来源:网络整理
导读:我有日期字符串,如2009-02-28 15:40:05 AEDST,并希望将其转换为SYSTEMTIME结构.到目前为止,我有: SYSTEMTIME st;FILETIME ft;SecureZeroMemory(st,sizeof(st));sscanf_s(contents,"%u-%u-%u %u:%u:%u",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.w
我有日期字符串,如2009-02-28 15:40:05 AEDST,并希望将其转换为SYSTEMTIME结构.到目前为止,我有:
SYSTEMTIME st; FILETIME ft; SecureZeroMemory(&st,sizeof(st)); sscanf_s(contents,"%u-%u-%u %u:%u:%u",&st.wYear,&st.wMonth,&st.wDay,&st.wHour,&st.wMinute,&st.wSecond); // Timezone correction SystemTimeToFileTime(&st,&ft); LocalFileTimeToFileTime(&ft,&ft); FileTimeToSystemTime(&ft,&st); 但是我的当地时区不是AEDST.所以我需要能够在转换为UTC时指定时区. 解决方法
看看这个:
https://web.archive.org/web/20140205072348/http://weseetips.com:80/2008/05/28/how-to-convert-local-system-time-to-utc-or-gmt/ // Get the local system time. SYSTEMTIME LocalTime = { 0 }; GetSystemTime( &LocalTime ); // Get the timezone info. TIME_ZONE_INFORMATION TimeZoneInfo; GetTimeZoneInformation( &TimeZoneInfo ); // Convert local time to UTC. SYSTEMTIME GmtTime = { 0 }; TzSpecificLocalTimeToSystemTime( &TimeZoneInfo,&LocalTime,&GmtTime ); // GMT = LocalTime + TimeZoneInfo.Bias // TimeZoneInfo.Bias is the difference between local time // and GMT in minutes. // Local time expressed in terms of GMT bias. float TimeZoneDifference = -( float(TimeZoneInfo.Bias) / 60 ); CString csLocalTimeInGmt; csLocalTimeInGmt.Format( _T("%ld:%ld:%ld + %2.1f Hrs"),GmtTime.wHour,GmtTime.wMinute,GmtTime.wSecond,TimeZoneDifference ); 问题:如何获取特定时区的TIME_TIMEZONE_INFORMATION? 不幸的是,你不能用win32 API做到这一点.参见MSDN和How do I get a specific TIME_ZONE_INFORMATION struct in Win32? 您将需要创建一个空变量并手动填充它,或使用标准C时间库. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 将Clickonce应用程序分发到Windows 8
- windows – 配置SCCM,以便可以从分发点下载文件名中带有加号
- windows-8 – Windows应用商店应用程序的图表(XAML C#)
- windows下 redis/tomcat 服务自启动
- 如何解决 Windows 实例出现身份验证错误及更正 CredSSP
- Windows下安装Python、pip、Django
- windows phone 7 – 本地化Windows Phone 7应用程序
- windows环境下的Anaconda安装与OpenCV机器视觉环境搭建
- windows – CryptGenRandom熵
- win2012 挂载硬盘即增加新硬盘方法
推荐文章
站长推荐
热点阅读