获取Windows时区信息(C ++ / MFC) [英] Getting Windows Time Zone Information (C++/MFC)

查看:934
本文介绍了获取Windows时区信息(C ++ / MFC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图:


  1. 获取用户选择时区时显示的时区名称列表从Windows控制面板(例如,(UTC-08:00)太平洋时间(美国和加拿大))。

通过阅读注册表中的CurrentVersion \Time Zones部分,我会这样做。


  1. 以字符串形式获取当前选择的时区。

我可以使用GetTimeZoneInformation()获取当前时区,但是这些名称与从注册表的CurrentVersion \ Time Zones部分检索的时区列表不匹配。例如,太平洋时间在时区列表中显示为(UTC-08:00)太平洋时间(美国和加拿大),但GetTimeZoneInformation()包含字符串太平洋标准时间和太平洋夏令时间。我需要找到一个对应于CurrentVersion \Time Zones名称的名称,以便我可以从列表中选择它。


  1. Get

我可以从UTC检索偏移量在timeZoneInformation.Bias,但这只是为当前选择的时区。我需要知道注册表中列出的任何区域的偏差(例如,(UC-07:00)山区时间(美国和加拿大),如果有效,则调整夏令时。

谢谢!

解决方案

Microsoft选择将您想要的字符串放在不同的区域



CurrentVersion \ Time Zones

中, strong>,yes是区域的名称。
是您想要的部分的值。



re:(UTC-08:00)太平洋时间(美国和加拿大)



这是在注册表值



资源DLL中有更多的字符串,由MUI_Display,MUI_Std和MUI_Dlt通常为@ tzres.dll,-220



要获取这些字符串,您需要将该资源DLL加载到内存和获取










还有在注册表项中(时区名称)是一个名为TZI的值。
这是一个二进制的blob(根据MSDN)看起来像这样:

  typedef struct _REG_TZI_FORMAT 
{
LONG Bias;
LONG StandardBias;
LONG DaylightBias;
SYSTEMTIME StandardDate;
SYSTEMTIME DaylightDate;
} REG_TZI_FORMAT;

其中各种BIAS以分钟为单位,使用方程式 UTC = local + theBias theBias Bias + StandardBias Bias + DaylightBias ,具体取决于相关日期。两个 SYSTEMTIME 值描述了过渡日期。


I’m trying to:

  1. Get a list of the time zone names as they appear in when the user selects a time zone from the Windows Control Panel (e.g., "(UTC-08:00) Pacific Time (US & Canada)").

I’m doing that by reading "CurrentVersion\Time Zones" section of the registry which works well.

  1. Get the currently selected time zone as a string.

I can get the current time zone using GetTimeZoneInformation(), but the names don’t match the list of time zones retrieved from "CurrentVersion\Time Zones" section of the registry. For example, Pacific time appears as "(UTC-08:00) Pacific Time (US & Canada)" in the list of time zones, but GetTimeZoneInformation() contains the strings "Pacific Standard Time" and "Pacific Daylight Time". I need to find a name that corresponds to the "CurrentVersion\Time Zones" names so I can select it from a list.

  1. Get the current offset (in minutes) between UTC and any other time zone based on the string name.

I can retrieve the offset from UTC in timeZoneInformation.Bias, but that’s only for the currently selected time zone. I need to know the "bias" from any zone as listed in the registry (e.g., "(UC-07:00) Mountain Time (US & Canada)" while adjusting for the daylight savings if in effect.

Thanks!

解决方案

Microsoft chooses to put the string you want in a different area, some strings are non trivial to retrieve. But parts of your question can be answered with the information you have already.

In CurrentVersion\Time Zones, yes are the names of the zones. Inside that key are the values for some of the parts you want.

re: "(UTC-08:00) Pacific Time (US & Canada)"

This is in the registry value "Display" under the zone name you have.

There are more strings in a resource DLL, specified by the values "MUI_Display", "MUI_Std" and "MUI_Dlt". It is usually something like "@tzres.dll,-220"

To get these strings you will need to load that resource DLL into memory and fetch those specific resources as UNICODE strings.

re: Offset in minutes of any timezone.

Also inside the registry key you have (the time zone name) is a value called "TZI". This is a binary blob that (according to the MSDN) looks like this:

typedef struct _REG_TZI_FORMAT
{
    LONG Bias;
    LONG StandardBias;
    LONG DaylightBias;
    SYSTEMTIME StandardDate;
    SYSTEMTIME DaylightDate;
} REG_TZI_FORMAT;

Where the various BIAS are in minutes, using the equation UTC = local + theBias and theBias is either Bias + StandardBias or Bias + DaylightBias depending on the date in question. The two SYSTEMTIME values describe the transition dates.

这篇关于获取Windows时区信息(C ++ / MFC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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