网站首页  词典首页

请输入您要查询的函数:

 

术语 settimezoneinformation
释义 SetTimeZoneInformation
语法:
C++
BOOL WINAPI SetTimeZoneInformation(
__in const TIME_ZONE_INFORMATION *lpTimeZoneInformation
);
SetTimeZoneInformation功能
设置当前的时区设置。这些设置控制协调通用时间(UTC)翻译为本地时间。
支持节省时间,从一年来的变化,使用SetDynamicTimeZoneInformation功能白天的界限。
参数
lpTimeZoneInformation [in]
一个 TIME_ZONE_INFORMATION结构,它包含了新设置的指针。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
应用程序必须有此功能SE_TIME_ZONE_NAME特权成功。这种特权是默认禁用。使用AdjustTokenPrivileges函数调用SetTimeZoneInformation之前启用的特权,然后禁用后SetTimeZoneInformation调用特权。有关更多信息,请运行特权。
Windows Server 2003和Windows XP/2000操作系统:应用程序必须具有SE_SYSTEMTIME_NAME特权。
要告知浏览器中的时区已经改变,发送WM_SETTINGCHANGE消息。
UTC与本地时间所有的翻译是根据以下公式:
星期日=本地时间+偏见
该偏差的差异,在几分钟内,UTC与本地时间。
实例
下面的示例显示当前的时区,然后调整时区一区,西部。旧的和新的时区名称显示。您也可以验证的变化使用控制面板中日期和时间。新的名称将显示在日期和作为当前时区的时间标签。新的时区显示在下拉时区选项卡的列表。要撤消这些更改,只需选择从下拉列表中旧的时区。
#define UNICODE 1
#define _UNICODE 1
#include
#include
#include
#include
int main()
{
TIME_ZONE_INFORMATION tziOld, tziNew, tziTest;
DWORD dwRet;
// Enable the required privilege
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_TIME_ZONE_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
// Retrieve the current time zone information
dwRet = GetTimeZoneInformation(&tziOld);
if(dwRet == TIME_ZONE_ID_STANDARD || dwRet == TIME_ZONE_ID_UNKNOWN)
wprintf(L"%s\\n", tziOld.StandardName);
else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
wprintf(L"%s\\n", tziOld.DaylightName);
else
{
printf("GTZI failed (%d)\\n", GetLastError());
return 0;
}
// Adjust the time zone information
ZeroMemory(&tziNew, sizeof(tziNew));
tziNew.Bias = tziOld.Bias + 60;
StringCchCopy(tziNew.StandardName, 32, L"Test Standard Zone");
tziNew.StandardDate.wMonth = 10;
tziNew.StandardDate.wDayOfWeek = 0;
tziNew.StandardDate.wDay = 5;
tziNew.StandardDate.wHour = 2;
StringCchCopy(tziNew.DaylightName, 32, L"Test Daylight Zone");
tziNew.DaylightDate.wMonth = 4;
tziNew.DaylightDate.wDayOfWeek = 0;
tziNew.DaylightDate.wDay = 1;
tziNew.DaylightDate.wHour = 2;
tziNew.DaylightBias = -60;
if( !SetTimeZoneInformation( &tziNew ) )
{
printf("STZI failed (%d)\\n", GetLastError());
return 0;
}
// Retrieve and display the newly set time zone information
dwRet = GetTimeZoneInformation(&tziTest);
if(dwRet == TIME_ZONE_ID_STANDARD || dwRet == TIME_ZONE_ID_UNKNOWN)
wprintf(L"%s\\n", tziTest.StandardName);
else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
wprintf(L"%s\\n", tziTest.DaylightName);
else printf("GTZI failed (%d)\\n", GetLastError());
// Disable the privilege
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return 1;
}

要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
GetTimeZoneInformation
SetDynamicTimeZoneInformation
时间函数
TIME_ZONE_INFORMATION
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==SetTimeZoneInformation Function
Sets the current time zone settings. These settings control translations from Coordinated Universal Time (UTC) to local time.
To support boundaries for daylight saving time that change from year to year, use the SetDynamicTimeZoneInformation function.
Syntax
C++
BOOL WINAPI SetTimeZoneInformation(
__in const TIME_ZONE_INFORMATION *lpTimeZoneInformation
);
Parameters
lpTimeZoneInformation [in]
A pointer to a TIME_ZONE_INFORMATION structure that contains the new settings.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
Remarks
An application must have the SE_TIME_ZONE_NAME privilege for this function to succeed. This privilege is disabled by default. Use the AdjustTokenPrivileges function to enable the privilege before calling SetTimeZoneInformation, and then to disable the privilege after the SetTimeZoneInformation call. For more information, see Running with Special Privileges .
Windows Server 2003 and Windows XP/2000: The application must have the SE_SYSTEMTIME_NAME privilege.
To inform Explorer that the time zone has changed, send the WM_SETTINGCHANGE message.
All translations between UTC and local time are based on the following formula:
UTC = local time + bias
The bias is the difference, in minutes, between UTC and local time.
Examples
The following example displays the current time zone, then adjusts the time zone one zone to the west. The old and new time zone names are displayed. You can also verify the changes using Date and Time in Control Panel. The new name is displayed on the Date&Time tab as the Current Time Zone. The new time zone is displayed in the drop-down list on the Time Zone tab. To undo these changes, simply choose your old time zone from the drop-down list.
#define UNICODE 1
#define _UNICODE 1
#include
#include
#include
#include
int main()
{
TIME_ZONE_INFORMATION tziOld, tziNew, tziTest;
DWORD dwRet;
// Enable the required privilege
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_TIME_ZONE_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
// Retrieve the current time zone information
dwRet = GetTimeZoneInformation(&tziOld);
if(dwRet == TIME_ZONE_ID_STANDARD || dwRet == TIME_ZONE_ID_UNKNOWN)
wprintf(L"%s\\n", tziOld.StandardName);
else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
wprintf(L"%s\\n", tziOld.DaylightName);
else
{
printf("GTZI failed (%d)\\n", GetLastError());
return 0;
}
// Adjust the time zone information
ZeroMemory(&tziNew, sizeof(tziNew));
tziNew.Bias = tziOld.Bias + 60;
StringCchCopy(tziNew.StandardName, 32, L"Test Standard Zone");
tziNew.StandardDate.wMonth = 10;
tziNew.StandardDate.wDayOfWeek = 0;
tziNew.StandardDate.wDay = 5;
tziNew.StandardDate.wHour = 2;
StringCchCopy(tziNew.DaylightName, 32, L"Test Daylight Zone");
tziNew.DaylightDate.wMonth = 4;
tziNew.DaylightDate.wDayOfWeek = 0;
tziNew.DaylightDate.wDay = 1;
tziNew.DaylightDate.wHour = 2;
tziNew.DaylightBias = -60;
if( !SetTimeZoneInformation( &tziNew ) )
{
printf("STZI failed (%d)\\n", GetLastError());
return 0;
}
// Retrieve and display the newly set time zone information
dwRet = GetTimeZoneInformation(&tziTest);
if(dwRet == TIME_ZONE_ID_STANDARD || dwRet == TIME_ZONE_ID_UNKNOWN)
wprintf(L"%s\\n", tziTest.StandardName);
else if( dwRet == TIME_ZONE_ID_DAYLIGHT )
wprintf(L"%s\\n", tziTest.DaylightName);
else printf("GTZI failed (%d)\\n", GetLastError());
// Disable the privilege
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return 1;
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
GetTimeZoneInformation
SetDynamicTimeZoneInformation
Time Functions
TIME_ZONE_INFORMATION
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms724944(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:28:12