本文整理汇总了C#中NodaTime.DateTimeZone.GetUtcOffset方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeZone.GetUtcOffset方法的具体用法?C# DateTimeZone.GetUtcOffset怎么用?C# DateTimeZone.GetUtcOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodaTime.DateTimeZone
的用法示例。
在下文中一共展示了DateTimeZone.GetUtcOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TimeZoneOffsetProvider
/// <summary>
/// Initializes a new instance of the <see cref="TimeZoneOffsetProvider"/> class
/// </summary>
/// <param name="timeZone">The time zone to provide offsets for</param>
/// <param name="utcStartTime">The start of the range of offsets</param>
/// <param name="utcEndTime">The en of the range of offsets</param>
public TimeZoneOffsetProvider(DateTimeZone timeZone, DateTime utcStartTime, DateTime utcEndTime)
{
_timeZone = timeZone;
// pad the end so we get the correct zone interval
utcEndTime += TimeSpan.FromDays(2*365);
var start = DateTimeZone.Utc.AtLeniently(LocalDateTime.FromDateTime(utcStartTime));
var end = DateTimeZone.Utc.AtLeniently(LocalDateTime.FromDateTime(utcEndTime));
var zoneIntervals = _timeZone.GetZoneIntervals(start.ToInstant(), end.ToInstant());
_discontinuities = new Queue<long>(zoneIntervals.Select(x => x.Start.ToDateTimeUtc().Ticks));
if (_discontinuities.Count == 0)
{
// end of discontinuities
_nextDiscontinuity = DateTime.MaxValue.Ticks;
_currentOffsetTicks = _timeZone.GetUtcOffset(Instant.FromDateTimeUtc(DateTime.UtcNow)).Ticks;
}
else
{
// get the offset just before the next discontinuity to initialize
_nextDiscontinuity = _discontinuities.Dequeue();
_currentOffsetTicks = _timeZone.GetUtcOffset(Instant.FromDateTimeUtc(new DateTime(_nextDiscontinuity - 1, DateTimeKind.Utc))).Ticks;
}
}
示例2: ChangeTimeZone
public void ChangeTimeZone(DateTimeZone dateTimeZone)
{
ZonedDateTime = new ZonedDateTime(ZonedDateTime.LocalDateTime, dateTimeZone, dateTimeZone.GetUtcOffset(Instant.FromDateTimeOffset(ZonedDateTime.ToDateTimeOffset())));
}