SetTimeZoneInformation 함수(timezoneapi.h)

현재 표준 시간대 설정을 설정합니다. 이러한 설정은 UTC(협정 세계시)에서 현지 시간으로의 변환을 제어합니다.

해마다 변경되는 일광 절약 시간에 대한 경계를 지원하려면 SetDynamicTimeZoneInformation 함수를 사용합니다.

구문

BOOL SetTimeZoneInformation(
  [in] const TIME_ZONE_INFORMATION *lpTimeZoneInformation
);

매개 변수

[in] lpTimeZoneInformation

새 설정을 포함하는 TIME_ZONE_INFORMATION 구조체에 대한 포인터입니다.

반환 값

함수가 성공하면 반환 값이 0이 아닙니다.

함수가 실패하면 반환 값은 0입니다. 확장 오류 정보를 가져오려면 GetLastError를 호출합니다.

설명

이 함수가 성공하려면 애플리케이션에 SE_TIME_ZONE_NAME 권한이 있어야 합니다. 이 권한은 기본적으로 사용하지 않도록 설정됩니다. AdjustTokenPrivileges 함수를 사용하여 SetTimeZoneInformation을 호출하기 전에 권한을 사용하도록 설정한 다음 SetTimeZoneInformation 호출 후 권한을 사용하지 않도록 설정합니다. 자세한 내용은 특별 권한으로 실행을 참조하세요.

Windows Server 2003 및 Windows XP/2000: 애플리케이션에는 SE_SYSTEMTIME_NAME 권한이 있어야 합니다.

중요

Windows Vista 및 Windows Server 2008부터 모든 현재 버전의 Windows를 통해 SetTimeZoneInformation 대신 SetDynamicTimeZoneInformation을 호출하여 시스템 표준 시간대 정보를 설정합니다. SetDynamicTimeZoneInformation 은 Windows 레지스트리의 동적 데이터에서 제공하는 표준 시간 및 일광 절약 시간제 변경의 전체 기록을 지원합니다. 애플리케이션에서 SetTimeZoneInformation을 사용하는 경우 시스템에 대한 동적 일광 절약 시간 지원이 비활성화되고 "현재 표준 시간대가 인식되지 않습니다. 유효한 표준 시간대를 선택하세요." Windows 표준 시간대 설정에서 사용자에게 표시됩니다.

표준 시간대가 변경되었음을 Explorer 알리려면 WM_SETTINGCHANGE 메시지를 보냅니다.

UTC와 현지 시간 간의 모든 번역은 다음 수식을 기반으로 합니다.

UTC = 현지 시간 + 바이어스

바이어스는 UTC와 현지 시간 간의 차이(분)입니다.

예제

다음 예제에서는 현재 표준 시간대를 표시한 다음 표준 시간대를 한 영역 서쪽으로 조정합니다. 이전 및 새 표준 시간대 이름이 표시됩니다. 제어판 날짜 및 시간을 사용하여 변경 내용을 확인할 수도 있습니다. 새 이름은 날짜&시간 탭에 현재 표준 시간대로 표시됩니다. 표준 시간대 탭의 드롭다운 목록에 새 표준 시간대 가 표시됩니다. 이러한 변경 내용을 실행 취소하려면 드롭다운 목록에서 이전 표준 시간대를 선택하기만 하면 됩니다.

#define UNICODE 1
#define _UNICODE 1

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <strsafe.h>

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;
}

요구 사항

   
지원되는 최소 클라이언트 Windows 2000 Professional[데스크톱 앱만]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 timezoneapi.h(Windows.h 포함)
라이브러리 Kernel32.lib
DLL Kernel32.dll

참고 항목

GetTimeZoneInformation

SetDynamicTimeZoneInformation

TIME_ZONE_INFORMATION

시간 함수