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


C# DateTimeOffset.Next方法代码示例

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


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

示例1: Next_ReturnsNextFridayProperly

    public void Next_ReturnsNextFridayProperly()
    {
        var friday = new DateTimeOffset(2009, 7, 10, 1, 0, 0, 0, TimeSpan.Zero);
        var reallyNextFriday = new DateTimeOffset(2009, 7, 17, 1, 0, 0, 0, TimeSpan.Zero);
        var nextFriday = friday.Next(DayOfWeek.Friday);

        Assert.AreEqual(reallyNextFriday, nextFriday);
    }
开发者ID:jin29neci,项目名称:FluentDateTime,代码行数:8,代码来源:DateTimeOffsetTests.cs

示例2: NextLast

        public void NextLast()
        {
            var date = new DateTimeOffset(2015, 8, 7, 0, 0, 0, TimeSpan.Zero);
            Assert.AreEqual(new DateTimeOffset(2015, 8, 10, 0, 0, 0, TimeSpan.Zero), date.Next(DayOfWeek.Monday));
            Assert.AreEqual(new DateTimeOffset(2015, 8, 14, 0, 0, 0, TimeSpan.Zero), date.Next(DayOfWeek.Friday));
            Assert.AreEqual(new DateTimeOffset(2015, 8, 9, 0, 0, 0, TimeSpan.Zero), date.Next(DayOfWeek.Sunday));
            Assert.AreEqual(new DateTimeOffset(2015, 8, 15, 0, 0, 0, TimeSpan.Zero), date.Next(DayOfWeek.Saturday));

            Assert.AreEqual(new DateTimeOffset(2015, 8, 3, 0, 0, 0, TimeSpan.Zero), date.Last(DayOfWeek.Monday));
            Assert.AreEqual(new DateTimeOffset(2015, 7, 31, 0, 0, 0, TimeSpan.Zero), date.Last(DayOfWeek.Friday));
            Assert.AreEqual(new DateTimeOffset(2015, 8, 2, 0, 0, 0, TimeSpan.Zero), date.Last(DayOfWeek.Sunday));
            Assert.AreEqual(new DateTimeOffset(2015, 8, 1, 0, 0, 0, TimeSpan.Zero), date.Last(DayOfWeek.Saturday));
        }
开发者ID:dterracino,项目名称:cadru,代码行数:13,代码来源:DateTimeOffsetExtensionsTests.cs

示例3: BasicTests

    public void BasicTests()
    {
        var now = DateTimeOffset.UtcNow;
        var expected = new DateTimeOffset(now.Year, now.Month, now.Day, 23, 59, 59, 999, TimeSpan.Zero);
        var actual = now.EndOfDay();
        Assert.AreEqual(expected, actual, " End of the day wrong");
        Assert.AreEqual(new DateTimeOffset(now.Year, now.Month, now.Day, 0, 0, 0, 0, TimeSpan.Zero), now.BeginningOfDay(), "Start of the day wrong");

        var firstBirthDay = new DateTimeOffset(1977, 12, 31, 17, 0, 0, 0, TimeSpan.Zero);
        Assert.AreEqual(firstBirthDay + new TimeSpan(1, 0, 5, 0, 0), firstBirthDay + 1.Days() + 5.Minutes());

        Assert.AreEqual(now + TimeSpan.FromDays(1), now.NextDay());
        Assert.AreEqual(now - TimeSpan.FromDays(1), now.PreviousDay());

        Assert.AreEqual(now + TimeSpan.FromDays(7), now.WeekAfter());
        Assert.AreEqual(now - TimeSpan.FromDays(7), now.WeekEarlier());

        Assert.AreEqual(new DateTimeOffset(2009, 1, 1, 0, 0, 0, 0, TimeSpan.Zero), new DateTimeOffset(2008, 12, 31, 0, 0, 0, TimeSpan.Zero).Add(1.Days()));
        Assert.AreEqual(new DateTimeOffset(2009, 1, 2, 0, 0, 0, 0, TimeSpan.Zero), new DateTimeOffset(2009, 1, 1, 0, 0, 0, 0, TimeSpan.Zero).Add(1.Days()));

        var sampleDate = new DateTimeOffset(2009, 1, 1, 13, 0, 0, 0, TimeSpan.Zero);
        Assert.AreEqual(new DateTimeOffset(2009, 1, 1, 12, 0, 0, 0, TimeSpan.Zero), sampleDate.Noon());
        Assert.AreEqual(new DateTimeOffset(2009, 1, 1, 0, 0, 0, 0, TimeSpan.Zero), sampleDate.Midnight());

        Assert.AreEqual(3.Days() + 3.Days(), 6.Days());
        Assert.AreEqual(102.Days() - 3.Days(), 99.Days());

        Assert.AreEqual(24.Hours(), 1.Days());

        sampleDate = new DateTimeOffset(2008, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
        Assert.AreEqual(3.Days().Since(sampleDate), sampleDate + 3.Days());

        var saturday = new DateTimeOffset(2008, 10, 25, 12, 0, 0, TimeSpan.Zero);
        Assert.AreEqual(new DateTimeOffset(2008, 11, 1, 12, 0, 0, TimeSpan.Zero), saturday.Next(DayOfWeek.Saturday));

        Assert.AreEqual(new DateTimeOffset(2008, 10, 18, 12, 0, 0, TimeSpan.Zero), saturday.Previous(DayOfWeek.Saturday));

        var nextWeek = DateTimeOffset.UtcNow + 1.Weeks();

        var tomorrow = DateTimeOffset.UtcNow + 1.Days();
        var yesterday = DateTimeOffset.UtcNow - 1.Days();
        var changedHourTo14H = DateTimeOffset.UtcNow.SetHour(14);
        var todayNoon = DateTimeOffset.UtcNow.Noon();
        var tomorrowNoon = DateTimeOffset.UtcNow.NextDay().Noon();
        var fiveDaysAgo = TimeSpanOffsetExtensions.Ago(5.Days());
        var twoDaysFromNow = TimeSpanOffsetExtensions.FromNow(2.Days());
        var nextYearSameDateAsTodayNoon = TimeSpanOffsetExtensions.FromNow(1.Years()).Noon();

        var twoWeeksFromNow = TimeSpanOffsetExtensions.FromNow(2.Weeks());

    }
开发者ID:jin29neci,项目名称:FluentDateTime,代码行数:51,代码来源:DateTimeOffsetTests.cs


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