最近研究了一下Windows 上的时区设置方法,记录在此,分享大家。
首先分析一下原理。经过一番研究,发现Windows平台上设置时区和以下因素有关系:
1. 设置时区时,使用API函数SetTimeZoneInformation来设置时区信息。这个API函数使用了一个结构“TIME_ZONE_INFORMATION”,其定义在winbase.h,具体如下:
typedef struct _TIME_ZONE_INFORMATION {
LONG Bias;
WCHAR StandardName[ 32 ];
SYSTEMTIME StandardDate;
LONG StandardBias;
WCHAR DaylightName[ 32 ];
SYSTEMTIME DaylightDate;
LONG DaylightBias;
} TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
Bias: 和0时区相差的分钟数
StandardName: 标准时间的名称
StandardDate:如果有夏令时的时区,这个结构确定了什么时间开始实行夏令时
StandardBias:标准时间下,和Bias的差别。通常为0
DaylightName:夏令时的名称
DaylightDate:结束夏令时的时间
DaylightBias:夏令时的时候,时间的偏差
另外,要注意一个公式:
</