2009-06-04 10 views
3

ねえ、私はTimeZoneInfoオブジェクトを持っていて、これからはTIME_ZONE_INFO構造体を作成したいと思います。TimeZoneInfo to TIME_ZONE_INFORMATION構造

バイアス、標準日、夏時間は非常に簡単です。しかし、私はstandardbiasとdaylightbiasを得ることに問題があります。だから問題は、どのように私はTimeZOneInfoオブジェクトから標準のバイアスを取得することができますか?DaylightBias(AdjustmentRule.DaylightDeltaがありますが、デルタではなくオフセットが必要です。

ありがとうございました。

答えて

0

TIME_ZONE_INFORMATIONヘルプは非常に便利です。それは、標準バイアスがほとんどのタイムゾーンで0であると言います。 standardbiasが0でないTime Zoneを持つことは、私にはあまり意味がありません。 「標準」とはどういう意味ですか?

DaylightDeltaは、Standard UTC OffsetとDaylight UTC Offsetの差です。 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; 
}