本文整理汇总了C#中System.TimeZoneInfo.TryGetTransitionOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TimeZoneInfo.TryGetTransitionOffset方法的具体用法?C# TimeZoneInfo.TryGetTransitionOffset怎么用?C# TimeZoneInfo.TryGetTransitionOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeZoneInfo
的用法示例。
在下文中一共展示了TimeZoneInfo.TryGetTransitionOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUtcOffsetHelper
// This is an helper method used by the method above, do not use this on its own.
private static TimeSpan GetUtcOffsetHelper (DateTime dateTime, TimeZoneInfo tz, out bool isDST)
{
if (dateTime.Kind == DateTimeKind.Local && tz != TimeZoneInfo.Local)
throw new Exception ();
isDST = false;
if (tz == TimeZoneInfo.Utc)
return TimeSpan.Zero;
TimeSpan offset;
if (tz.TryGetTransitionOffset(dateTime, out offset, out isDST))
return offset;
if (dateTime.Kind == DateTimeKind.Utc) {
var utcRule = tz.GetApplicableRule (dateTime);
if (utcRule != null && tz.IsInDST (utcRule, dateTime)) {
isDST = true;
return tz.BaseUtcOffset + utcRule.DaylightDelta;
}
return tz.BaseUtcOffset;
}
DateTime stdUtcDateTime;
if (!TryAddTicks (dateTime, -tz.BaseUtcOffset.Ticks, out stdUtcDateTime, DateTimeKind.Utc))
return tz.BaseUtcOffset;
var tzRule = tz.GetApplicableRule (stdUtcDateTime);
DateTime dstUtcDateTime = DateTime.MinValue;
if (tzRule != null) {
if (!TryAddTicks (stdUtcDateTime, -tzRule.DaylightDelta.Ticks, out dstUtcDateTime, DateTimeKind.Utc))
return tz.BaseUtcOffset;
}
if (tzRule != null && tz.IsInDST (tzRule, stdUtcDateTime) && tz.IsInDST (tzRule, dstUtcDateTime)) {
isDST = true;
return tz.BaseUtcOffset + tzRule.DaylightDelta;
}
return tz.BaseUtcOffset;
}
示例2: GetUtcOffsetHelper
// This is an helper method used by the method above, do not use this on its own.
private static TimeSpan GetUtcOffsetHelper (DateTime dateTime, TimeZoneInfo tz, out bool isDST)
{
if (dateTime.Kind == DateTimeKind.Local && tz != TimeZoneInfo.Local)
throw new Exception ();
isDST = false;
if (tz == TimeZoneInfo.Utc)
return TimeSpan.Zero;
TimeSpan offset;
if (tz.TryGetTransitionOffset(dateTime, out offset, out isDST))
return offset;
if (dateTime.Kind == DateTimeKind.Utc) {
var utcRule = tz.GetApplicableRule (dateTime);
if (utcRule != null && tz.IsInDST (utcRule, dateTime)) {
isDST = true;
return tz.BaseUtcOffset + utcRule.DaylightDelta;
}
return tz.BaseUtcOffset;
}
DateTime stdUtcDateTime;
if (!TryAddTicks (dateTime, -tz.BaseUtcOffset.Ticks, out stdUtcDateTime, DateTimeKind.Utc))
return tz.BaseUtcOffset;
var tzRule = tz.GetApplicableRule (stdUtcDateTime);
DateTime dstUtcDateTime = DateTime.MinValue;
if (tzRule != null) {
if (!TryAddTicks (stdUtcDateTime, -tzRule.DaylightDelta.Ticks, out dstUtcDateTime, DateTimeKind.Utc))
return tz.BaseUtcOffset;
}
if (tzRule != null && tz.IsInDST (tzRule, stdUtcDateTime)) {
// Replicate what .NET does when given a time which falls into the hour which is lost when
// DST starts. isDST should always be true but the offset should be BaseUtcOffset without the
// DST delta while in that hour.
isDST = true;
if (tz.IsInDST (tzRule, dstUtcDateTime)) {
return tz.BaseUtcOffset + tzRule.DaylightDelta;
} else {
return tz.BaseUtcOffset;
}
}
return tz.BaseUtcOffset;
}