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


C# DateTimeZone.GetZoneIntervals方法代码示例

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


在下文中一共展示了DateTimeZone.GetZoneIntervals方法的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;
            }
        }
开发者ID:jetq88,项目名称:Lean,代码行数:31,代码来源:TimeZoneOffsetProvider.cs

示例2: DumpZone

 private static void DumpZone(DateTimeZone zone, Options options)
 {
     Console.Write("{0}\r\n", zone.Id);
     var initial = zone.GetZoneInterval(Instant.MinValue);
     Console.Write("Initially: {0} {1} {2}\r\n",
         OffsetPattern.Format(initial.WallOffset),
         initial.Savings != Offset.Zero ? "daylight" : "standard",
         initial.Name);
     foreach (var zoneInterval in zone.GetZoneIntervals(options.Start, options.End)
         .Where(zi => zi.HasStart && zi.Start >= options.Start))
     {
         Console.Write("{0} {1} {2} {3}\r\n",
             InstantPattern.Format(zoneInterval.Start),
             OffsetPattern.Format(zoneInterval.WallOffset),
             zoneInterval.Savings != Offset.Zero ? "daylight" : "standard",
             zoneInterval.Name);
     }
 }
开发者ID:wondertrap,项目名称:nodatime,代码行数:18,代码来源:Program.cs


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