2009-06-04 2 views
3

안녕하세요, 저는 TimeZoneInfo 개체를 가지고 있으며이 개체에서 TIME_ZONE_INFO 구조체를 만들고 싶습니다.TimeZoneInfo to TIME_ZONE_INFORMATION 구조

바이어스, 표준 시각 및 주간 기록은 매우 쉽게 얻을 수 있습니다. 그러나 standardbias와 daylightbias를 얻는 데 문제가 있습니다. 그래서 질문은, 어떻게 TimeZOneInfo 객체에서 standardbias를 얻을 수 있습니까? 그리고 DaylightBias (AdjustmentRule.DaylightDelta가 있습니다. 그러나 델타가 아닌 오프셋이 필요하다는 것을 알 수 있듯이)에서 같은 것을 얻을 수있는 방법은 무엇입니까?

감사합니다.

답변

0

TIME_ZONE_INFORMATION 도움말은 매우 유용합니다. 그것은 standardbias가 대부분의 표준 시간대에 0이라고 말합니다. standardbias가 0이 아닌 표준 시간대를 갖는 것은 나에게별로 의미가 없습니다. "표준"이 의미하는 것이 아닙니까?

DaylightDelta는 표준 UTC 오프셋과 일광 UTC 오프셋의 차이입니다. DaylightBias는 동일한 방식으로 정의되므로 DaylightDelta가 DaylightBias입니다.

지금은 해킹 할 수 없지만 시간대의 데이터로 놀아 보시는 것이 좋습니다. 또는 Win32 개체를 사용하여 을 사용할 수있는 방법이 있습니까? 개체를 만드는 대신 적절한 TimeZoneInfo에 대한 TIME_ZONE_INFORMATION 구조체를 가져 오시겠습니까? DYNAMIC_TIME_ZONE_INFORMATION.StandardName에 TimeZoneInfo.StandardName을 지정하여 GetTimeZoneInformationForYear과 같은 것입니까?

1

이 코드를 CrankedUp (TIME_ZONE_INFORMATION을 읽음)를 사용한 결과와 비교해 보았는데 그 결과는 Windows XP SP3 시스템에서 동일합니다. 결과는 다를 수 있습니다.

TimeZoneInfo.AdjustmentRule[] adjustmentRules = timeZoneInfo.GetAdjustmentRules(); 
TimeZoneInfo.AdjustmentRule adjustmentRule = null; 
if (adjustmentRules.Length > 0) 
{ 
    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null. 
    adjustmentRule = adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd); 
} 

double bias = -timeZoneInfo.BaseUtcOffset.TotalMinutes; // I'm not sure why this number needs to be negated, but it does. 
string daylightName = timeZoneInfo.DaylightName; 
string standardName = timeZoneInfo.StandardName; 
double daylightBias = adjustmentRule == null ? -60 : -adjustmentRule.DaylightDelta.TotalMinutes; // Not sure why default is -60, or why this number needs to be negated, but it does. 
int daylightDay = 0; 
int daylightDayOfWeek = 0; 
int daylightHour = 0; 
int daylightMonth = 0; 
int standardDay = 0; 
int standardDayOfWeek = 0; 
int standardHour = 0; 
int standardMonth = 0; 

if (adjustmentRule != null) 
{ 
    TimeZoneInfo.TransitionTime daylightTime = adjustmentRule.DaylightTransitionStart; 
    TimeZoneInfo.TransitionTime standardTime = adjustmentRule.DaylightTransitionEnd; 

    // Valid values depend on IsFixedDateRule: http://msdn.microsoft.com/en-us/library/system.timezoneinfo.transitiontime.isfixeddaterule. 
    daylightDay = daylightTime.IsFixedDateRule ? daylightTime.Day : daylightTime.Week; 
    daylightDayOfWeek = daylightTime.IsFixedDateRule ? -1 : (int)daylightTime.DayOfWeek; 
    daylightHour = daylightTime.TimeOfDay.Hour; 
    daylightMonth = daylightTime.Month; 

    standardDay = standardTime.IsFixedDateRule ? standardTime.Day : standardTime.Week; 
    standardDayOfWeek = standardTime.IsFixedDateRule ? -1 : (int)standardTime.DayOfWeek; 
    standardHour = standardTime.TimeOfDay.Hour; 
    standardMonth = standardTime.Month; 
}