C#WIndows CE Compact Framework 2.0设置系统时区
我想在windows CE Mobile中以编程方式更改系统时区??我该怎么做 我读了一些帖子,但我没能做到C#WIndows CE Compact Framework 2.0设置系统时区,c#,compact-framework,windows-ce,C#,Compact Framework,Windows Ce,我想在windows CE Mobile中以编程方式更改系统时区??我该怎么做 我读了一些帖子,但我没能做到 有人能提供一个示例代码来实现它吗?如果您通过DST,这很容易,但很棘手: 这有用吗 编辑:添加了TZ信息数据库信息: 看 为了获得TZ信息,我使用了以下C/C++代码: ... typedef void (*INITCITYDB)(void); typedef void (*UNINITCITYDB)(void); typedef void (*LOADTZDATA)(void); ty
有人能提供一个示例代码来实现它吗?如果您通过DST,这很容易,但很棘手: 这有用吗 编辑:添加了TZ信息数据库信息: 看 为了获得TZ信息,我使用了以下C/C++代码:
...
typedef void (*INITCITYDB)(void);
typedef void (*UNINITCITYDB)(void);
typedef void (*LOADTZDATA)(void);
typedef void (*FREETZDATA)(void);
typedef int (*GETNUMZONES)(void);
typedef void * (*GETTZDATABYOFFSET)(int, int*);
typedef void * (*GETTZDATA)(int);
struct TZData
{
TCHAR *Name;
TCHAR *ShortName;
TCHAR *DSTName;
int GMTOffset;
int DSTOffset;
};
...
然后用这个来获取信息
...
int getCityDB()
{
TZData *pTZ = NULL;
int index;
// load the library
HINSTANCE hLib = LoadLibrary(_T("CityDB.dll"));
if (hLib==NULL)
return -1;
// load the CityDB functions
INITCITYDB InitCityDB = (INITCITYDB)GetProcAddress(
hLib, _T("InitCityDb"));
UNINITCITYDB UninitCityDB = (UNINITCITYDB)GetProcAddress(
hLib, _T("UninitCityDb"));
LOADTZDATA ClockLoadAllTimeZoneData = (LOADTZDATA)GetProcAddress(
hLib, _T("ClockLoadAllTimeZoneData"));
FREETZDATA ClockFreeAllTimeZoneData = (FREETZDATA)GetProcAddress(
hLib, _T("ClockFreeAllTimeZoneData"));
GETNUMZONES ClockGetNumTimezones = (GETNUMZONES)GetProcAddress(
hLib, _T("ClockGetNumTimezones"));
GETTZDATABYOFFSET ClockGetTimeZoneDataByOffset =
(GETTZDATABYOFFSET)GetProcAddress(hLib, _T("ClockGetTimeZoneDataByOffset"));
GETTZDATA ClockGetTimeZoneData = (GETTZDATA)GetProcAddress(
hLib, _T("ClockGetTimeZoneData"));
// Init the library
InitCityDB();
// load the TZ data
ClockLoadAllTimeZoneData();
// find out how many zones are defined
int zoneCount = ClockGetNumTimezones();
...
现在,您可以遍历所有数据,有关详细信息,请参阅github代码:
...
wsprintf(wBuff, L"=================CityDB====================\n");
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
// interate through them all
for(int zone = 0 ; zone < zoneCount ; zone++)
{
// these are pointers to a timezone data struct
pTZ = (TZData*)ClockGetTimeZoneDataByOffset(zone, &index);
wsprintf(wBuff, L"index: %i\n", index );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tshort name: %s\n", pTZ->ShortName );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tname: %s\n", pTZ->Name );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tGMT offset: %i\n", pTZ->GMTOffset );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tdst name: %s\n", pTZ->DSTName );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tDST offset: %i\n", pTZ->DSTOffset );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
}
CloseHandle(hFile);
// unload the TZ data
ClockFreeAllTimeZoneData();
// uninit the library
UninitCityDB();
...
另请参见我在上的帖子,了解其工作原理。我仍然有疑问。我在哪里可以得到所有时区的所有偏差值和标准名称的列表??
...
wsprintf(wBuff, L"=================CityDB====================\n");
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
// interate through them all
for(int zone = 0 ; zone < zoneCount ; zone++)
{
// these are pointers to a timezone data struct
pTZ = (TZData*)ClockGetTimeZoneDataByOffset(zone, &index);
wsprintf(wBuff, L"index: %i\n", index );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tshort name: %s\n", pTZ->ShortName );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tname: %s\n", pTZ->Name );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tGMT offset: %i\n", pTZ->GMTOffset );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tdst name: %s\n", pTZ->DSTName );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
wsprintf(wBuff, L"\tDST offset: %i\n", pTZ->DSTOffset );
wcstombs(buff, wBuff, sizeof(wBuff)*sizeof(TCHAR));
WriteFile(hFile, buff, strlen(buff), &numWritten, NULL);
}
CloseHandle(hFile);
// unload the TZ data
ClockFreeAllTimeZoneData();
// uninit the library
UninitCityDB();
...
index: 95
short name: GMT+1 Prague,Budapest
name: Central Europe Standard Time
GMT offset: -60
dst name: Central Europe Daylight Time
DST offset: 0
...
index: 110
short name: GMT+1 Berlin,Rome
name: W. Europe Standard Time
GMT offset: -60
dst name: W. Europe Daylight Time
DST offset: 0