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


C# LocalDateTime.PlusHours方法代码示例

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


在下文中一共展示了LocalDateTime.PlusHours方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsoDayOfWeek_AroundEpoch

 public void IsoDayOfWeek_AroundEpoch()
 {
     // Test about couple of months around the Unix epoch. If that works, I'm confident the rest will.
     LocalDateTime dateTime = new LocalDateTime(1969, 12, 1, 0, 0);
     for (int i = 0; i < 60; i++)
     {
         // Check once per hour of the day, just in case something's messed up based on the time of day.
         for (int hour = 0; hour < 24; hour++)
         {
             Assert.AreEqual(BclConversions.ToIsoDayOfWeek(dateTime.ToDateTimeUnspecified().DayOfWeek),
                 dateTime.IsoDayOfWeek);
             dateTime = dateTime.PlusHours(1);
         }
     }
 }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:15,代码来源:LocalDateTimeTest.cs

示例2: Addition_Duration

        public void Addition_Duration()
        {
            const int minutes = 23;
            const int hours = 3;
            const int milliseconds = 40000;
            const long seconds = 321;
            const long nanoseconds = 12345;
            const long ticks = 5432112345;

            // Test all three approaches... not bothering to check a different calendar,
            // but we'll use two different offsets.
            OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
            Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9);
            OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1));
            Assert.AreEqual(expected, start + duration);
            Assert.AreEqual(expected, start.Plus(duration));
            Assert.AreEqual(expected, OffsetDateTime.Add(start, duration));

            Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours));
            Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours));

            Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes));
            Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes));

            Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds));
            Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds));

            Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds));
            Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds));

            Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks));
            Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks));

            Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds));
            Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:36,代码来源:OffsetDateTimeTest.cs

示例3: PlusHours_CrossingDayBoundary

 public void PlusHours_CrossingDayBoundary()
 {
     LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8);
     LocalDateTime expected = new LocalDateTime(2011, 4, 3, 8, 15, 8);
     Assert.AreEqual(expected, start.PlusHours(20));
     Assert.AreEqual(start, start.PlusHours(20).PlusHours(-20));
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:LocalDateTimeTest.PlusUnit.cs

示例4: PlusHours_CrossingYearBoundary

 public void PlusHours_CrossingYearBoundary()
 {
     // Christmas day + 10 days and 1 hour
     LocalDateTime start = new LocalDateTime(2011, 12, 25, 12, 15, 8);
     LocalDateTime expected = new LocalDateTime(2012, 1, 4, 13, 15, 8);
     Assert.AreEqual(expected, start.PlusHours(241));
     Assert.AreEqual(start, start.PlusHours(241).PlusHours(-241));
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:8,代码来源:LocalDateTimeTest.PlusUnit.cs

示例5: PlusHours_Simple

 public void PlusHours_Simple()
 {
     LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8);
     LocalDateTime expectedForward = new LocalDateTime(2011, 4, 2, 14, 15, 8);
     LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 10, 15, 8);
     Assert.AreEqual(expectedForward, start.PlusHours(2));
     Assert.AreEqual(expectedBackward, start.PlusHours(-2));
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:8,代码来源:LocalDateTimeTest.PlusUnit.cs


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