如题,用SetTimeZoneInformation设置了时区信息后,还要设置系统时间和本地时间的吗?
夏令时又该如何设置啊?
谢谢!
------解决方案--------------------
1 SetTimeZoneInformation does not change the clock and therefore will not affect subsequent calls to GetLocalTime. SetTimeZoneInformation only affects subsequent calls to GetSystemTime.
SetTimeZoneInformation does not save the newly written data into the persistent registry. To write the data permanently, you need to make the following call: RegFlushKey(HKEY_LOCAL_MACHINE). For more information, see RegFlushKey.
2 设置夏令时好像可以用SetDaylightTime函数:
void SetDaylightTime(
DWORD dst
);
Parameters
dst
[in] Integer that indicates whether or not day light savings time is in effect.
A value of 1 indicates that daylight saving time is in effect.
A value of zero indicates that standard time is in effect.
------解决方案--------------------
调用SetTimeZoneInformation 并不会改变时钟,也就是本地时间不变,但时区变了,所以GetLocalTime获取的系统时间会改变。所以我觉的调用SetTimeZoneInformation 之后,不需要设置系统时间或者本地时间。
------解决方案--------------------
在winCE下设置夏令时,只需修改LocalMachine下的SOFTWARE\\Microsoft\\Clock键下的AutoDST变量的值即可
可通过下面函数操作:
static BOOL SetDaylightSavingTime( DWORD Value )
{
HKEY hKey=NULL;
if ( ERROR_SUCCESS != RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Clock"), 0, 0, &hKey) )
return FALSE;
if ( ERROR_SUCCESS != RegSetValueEx( hKey,TEXT("AutoDST"), 0, REG_DWORD, (BYTE *)&Value, sizeof(Value) ) ) return FALSE;
RegCloseKey( hKey );
return TRUE;
}
------解决方案--------------------
------解决方案--------------------
使用SetTimeZoneInformation设置时区信息
- C/C++ code
TIME_ZONE_INFORMATION tm; GetTimeZoneInformation(&tm); tm.Bias = -480; tm.StandardName[0] = 20013; tm.StandardName[1] = 22269; tm.StandardName[2] = 26631; tm.StandardName[3] = 20934; tm.StandardName[4] = 26102; tm.StandardName[5] = 38388; tm.DaylightName[0] = 20013; tm.DaylightName[1] = 22269; tm.DaylightName[2] = 26631; tm.DaylightName[3] = 20934; tm.DaylightName[4] = 26102; tm.DaylightName[5] = 38388; if(SetTimeZoneInformation(&tm)==0) {}