当前位置: 首页>>代码示例>>C#>>正文


C# TimeZoneInfo.IsInDST方法代码示例

本文整理汇总了C#中System.TimeZoneInfo.IsInDST方法的典型用法代码示例。如果您正苦于以下问题:C# TimeZoneInfo.IsInDST方法的具体用法?C# TimeZoneInfo.IsInDST怎么用?C# TimeZoneInfo.IsInDST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeZoneInfo的用法示例。


在下文中一共展示了TimeZoneInfo.IsInDST方法的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;
		}
开发者ID:barsgroup,项目名称:linux-packaging-mono,代码行数:44,代码来源:TimeZoneInfo.cs

示例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;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:51,代码来源:TimeZoneInfo.cs


注:本文中的System.TimeZoneInfo.IsInDST方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。