从GMT偏移量获取时区名称 [英] Getting a Timezone name from a GMT offset

查看:118
本文介绍了从GMT偏移量获取时区名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

C ++中是否有可以将GMT/UTC偏移量转换为TimeZone名称的API?

提前谢谢.

例如-5 =东部时间

Hi All

Is there any API in C++ which can convert the GMT/UTC offsets to TimeZone names?

Thanks in advance.

e.g. -5 = Eastern Time

推荐答案

hello

您可以从下面的代码中获取时区值


hello

you can get time zone value from the below code


TIME_ZONE_INFORMATION tz = {0};
STimeZoneFromRegistry binary_data;
DWORD size = sizeof(binary_data);
HKEY hk = NULL;
TCHAR zone_key[] = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\Central Standard Time");
if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE, zone_key, 0, KEY_QUERY_VALUE, &hk) == ERROR_SUCCESS) &&
 (RegQueryValueEx(hk, "TZI", NULL, NULL, (BYTE *) &binary_data, &size) == ERROR_SUCCESS))
{
 tz.Bias = binary_data.Bias;
 tz.DaylightBias = binary_data.DaylightBias;
 tz.DaylightDate = binary_data.DaylightDate;
 tz.StandardBias = binary_data.StandardBias;
 tz.StandardDate = binary_data.StandardDate;
}

struct STimeZoneFromRegistry
{
 long  Bias;
 long  StandardBias;
 long  DaylightBias;
 SYSTEMTIME StandardDate;
 SYSTEMTIME DaylightDate;
};


古拉夫

谢谢.

但是我的要求有些不同.只需通过GMT偏移量,我就需要获取时区名称.迭代注册表中所有可用的键以检查偏移量可能有助于映射名称.

相反,我从注册表中对所有时区的映射进行了硬编码,并在运行时检索了我所需的内容.

再次感谢.
Hi Gourav

Thanks.

But my requirement is a little different. Just by having the GMT offset, i need to get the Time zone name. Iterating all keys available in the registry to check the offset might help in mapping the name.

Instead i hardcoded the mapping for all time zones from registry and retrieved what i require at runtime.

Thanks again.


这篇关于从GMT偏移量获取时区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆