當前位置: 首頁>>代碼示例>>C#>>正文


C# DateTime.NextTime方法代碼示例

本文整理匯總了C#中System.DateTime.NextTime方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.NextTime方法的具體用法?C# DateTime.NextTime怎麽用?C# DateTime.NextTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.NextTime方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: NextTimeMinuteTest

 public void NextTimeMinuteTest()
 {
     string timeString = "* * * * *"; // Every Minute of every hour of everyday
     var time = new DateTime(2009, 1, 1, 6, 1, 34, DateTimeKind.Utc); // 2009 - Jan - 1 06:01:34 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 2, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 06:02:00 UTC
     time = time.NextTime(timeString);
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 3, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 06:03:00 UTC
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:8,代碼來源:CronStringParserFixture.cs

示例2: NextTimeMonthlyTest

 public void NextTimeMonthlyTest()
 {
     string timeString = "0 0 1 * *"; // first of the month at midnight
     var time = new DateTime(2009, 1, 1, 6, 1, 24, DateTimeKind.Utc); // 2009 - Jan - 1 06:01:24 UTC
     Assert.AreEqual(new DateTime(2009, 2, 1, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Feb - 1 00:00:00 UTC
     timeString = "15 1 1,15 * *"; // 1:15 AM on the 1st and 15th of the month
     Assert.AreEqual(new DateTime(2009, 1, 15, 1, 15, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 15 01:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 2, 1, 1, 15, 0, DateTimeKind.Utc), time.AddDays(15).NextTime(timeString)); // 2009 - Feb - 1 01:15:00 UTC
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:9,代碼來源:CronStringParserFixture.cs

示例3: NextTimeHourlyTest

 public void NextTimeHourlyTest()
 {
     string timeString = "0 * * * *"; // the top every hour of everyday
     var time = new DateTime(2009, 1, 1, 6, 1, 24, DateTimeKind.Utc); // 2009 - Jan - 1 06:01:24 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 7, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 07:00:00 UTC
     timeString = "0,30 * * * *"; // every half hour
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 30, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 07:00:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 7, 0, 0, DateTimeKind.Utc), time.AddMinutes(30).NextTime(timeString)); // 2009 - Jan - 1 07:00:00 UTC
     timeString = "0,15,30,45 * * * *"; // every quarter hour
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 15, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 07:00:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 30, 0, DateTimeKind.Utc), time.AddMinutes(15).NextTime(timeString)); // 2009 - Jan - 1 06:30:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 45, 0, DateTimeKind.Utc), time.AddMinutes(30).NextTime(timeString)); // 2009 - Jan - 1 06:45:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 7, 00, 0, DateTimeKind.Utc), time.AddMinutes(45).NextTime(timeString)); // 2009 - Jan - 1 07:00:00 UTC
     timeString = "3,18,33,48 * * * *"; // every quarter hour + three minutes
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 03, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 06:18:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 18, 0, DateTimeKind.Utc), time.AddMinutes(15).NextTime(timeString)); // 2009 - Jan - 1 06:18:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 33, 0, DateTimeKind.Utc), time.AddMinutes(30).NextTime(timeString)); // 2009 - Jan - 1 06:33:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 48, 0, DateTimeKind.Utc), time.AddMinutes(45).NextTime(timeString)); // 2009 - Jan - 1 06:48:00 UTC 
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:19,代碼來源:CronStringParserFixture.cs

示例4: NextTimeDailyTest

 public void NextTimeDailyTest()
 {
     string timeString = "0 0 * * *"; // Daily at midnight
     var time = new DateTime(2009, 1, 1, 6, 1, 24, DateTimeKind.Utc); // 2009 - Jan - 1 06:01:24 UTC
     Assert.AreEqual(new DateTime(2009, 1, 2, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 2 00:00:00 UTC
     timeString = "0 7,19 * * *"; // an hour after each shift
     Assert.AreEqual(new DateTime(2009, 1, 1, 7, 00, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 07:00:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 19, 00, 0, DateTimeKind.Utc), time.AddHours(1).NextTime(timeString)); // 2009 - Jan - 1 19:00:00 UTC
     timeString = "20 6,18 * * *"; // an 20 minutes after each shift
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 20, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 06:20:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 18, 20, 0, DateTimeKind.Utc), time.AddHours(1).NextTime(timeString)); // 2009 - Jan - 1 18:20:00 UTC
     timeString = "15 0,3,6,9,12,15,18,21 * * *"; // every three hours
     Assert.AreEqual(new DateTime(2009, 1, 1, 6, 15, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Jan - 1 06:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 9, 15, 0, DateTimeKind.Utc), time.AddHours(3).NextTime(timeString)); // 2009 - Jan - 1 9:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 12, 15, 0, DateTimeKind.Utc), time.AddHours(6).NextTime(timeString)); // 2009 - Jan - 1 12:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 15, 15, 0, DateTimeKind.Utc), time.AddHours(9).NextTime(timeString)); // 2009 - Jan - 1 15:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 18, 15, 0, DateTimeKind.Utc), time.AddHours(12).NextTime(timeString)); // 2009 - Jan - 1 18:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 1, 21, 15, 0, DateTimeKind.Utc), time.AddHours(15).NextTime(timeString)); // 2009 - Jan - 1 21:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 2, 0, 15, 0, DateTimeKind.Utc), time.AddHours(18).NextTime(timeString)); // 2009 - Jan - 2 00:15:00 UTC
     Assert.AreEqual(new DateTime(2009, 1, 2, 3, 15, 0, DateTimeKind.Utc), time.AddHours(21).NextTime(timeString)); // 2009 - Jan - 2 00:03:00 UTC
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:21,代碼來源:CronStringParserFixture.cs

示例5: NextTimeYearlyTest

        public void NextTimeYearlyTest()
        {
            string timeString = "0 0 1 3 *"; // first of March at midnight
            var time = new DateTime(2009, 1, 1, 6, 1, 24, DateTimeKind.Utc); // 2009 - Jan - 1 06:01:24 UTC
            Assert.AreEqual(new DateTime(2009, 3, 1, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Mar - 1 00:00:00 UTC
            Assert.AreEqual(new DateTime(2010, 3, 1, 0, 0, 0, DateTimeKind.Utc), time.AddMonths(3).NextTime(timeString)); // 2010 - Mar - 1 00:00:00 UTC
            timeString = "0 0 1 3,4 *";
            Assert.AreEqual(new DateTime(2009, 3, 1, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Mar - 1 00:00:00 UTC
            time = time.NextTime(timeString);  // 2009 - Mar - 1 00:00:00 UTC
            Assert.AreEqual(new DateTime(2009, 4, 1, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // 2009 - Apr - 1 00:00:00 UTC

        }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:12,代碼來源:CronStringParserFixture.cs

示例6: FindLastSundayOfApril

 public void FindLastSundayOfApril()
 {
     string timeString = "0 0 * 4,6 1L";
     var time = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     Assert.AreEqual(new DateTime(2010, 4, 25, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString));
     Assert.AreEqual(new DateTime(2010, 6, 27, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString).NextTime(timeString));
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:7,代碼來源:CronStringParserFixture.cs

示例7: FindDaylightSavingTime1966End

        public void FindDaylightSavingTime1966End()
        {
            string timeString = "0 2 * 10 1L";
            var time = new DateTime(1986, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            Assert.AreEqual(new DateTime(1986, 10, 26, 2, 0, 0, DateTimeKind.Utc), time.NextTime(timeString));

        }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:7,代碼來源:CronStringParserFixture.cs

示例8: FindDaylightSavingTime1987Start

 public void FindDaylightSavingTime1987Start()
 {
     string timeString = "0 2 * 4 1";
     var time = new DateTime(2006, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     Assert.AreEqual(new DateTime(2006, 4, 2, 2, 0, 0, DateTimeKind.Utc), time.NextTime(timeString));
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:6,代碼來源:CronStringParserFixture.cs

示例9: FindDaylightSavingTime2007End

 public void FindDaylightSavingTime2007End()
 {
     string timeString = "0 2 * 11 1";
     var time = new DateTime(2009, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     Assert.AreEqual(new DateTime(2009, 11, 1, 2, 0, 0, DateTimeKind.Utc), time.NextTime(timeString));
     time = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     Assert.AreEqual(new DateTime(2010, 11, 7, 2, 0, 0, DateTimeKind.Utc), time.NextTime(timeString));
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:8,代碼來源:CronStringParserFixture.cs

示例10: FindDaylightSavingTime2007Start

 public void FindDaylightSavingTime2007Start()
 {
     string timeString = "0 2 * 3 1";
     var time = new DateTime(2009, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     Assert.AreEqual(new DateTime(2009, 3, 8, 2, 0, 0, DateTimeKind.Utc), time.NextTime(timeString).NextTime(timeString));
     time = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     Assert.AreEqual(new DateTime(2010, 3, 14, 2, 0, 0, DateTimeKind.Utc), time.NextTime(timeString).NextTime(timeString));
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:8,代碼來源:CronStringParserFixture.cs

示例11: NextTimeYearRangeTest

 public void NextTimeYearRangeTest()
 {
     string timeString = "0 0 11 11 * 2011-2015"; //veterans day 2011
     var time = new DateTime(2009, 10, 30, 5, 4, 12, DateTimeKind.Utc); // it is friday morning
     Assert.AreEqual(new DateTime(2011, 11, 11, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // veterans day
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:6,代碼來源:CronStringParserFixture.cs

示例12: NextTimePastYearTest

 public void NextTimePastYearTest()
 {
     string timeString = "0 0 11 11 * 2011"; //veterans day 2011
     var time = new DateTime(2013, 10, 30, 5, 4, 12, DateTimeKind.Utc);
     time.NextTime(timeString);
     Assert.Fail();
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:7,代碼來源:CronStringParserFixture.cs

示例13: NextTimeWeeklyTest

 public void NextTimeWeeklyTest()
 {
     string timeString = "0 0 * * 2,4,6"; //midnight on monday, wendesday and friday
     var time = new DateTime(2009, 10, 30, 5, 4, 12, DateTimeKind.Utc); // it is friday morning
     Assert.AreEqual(new DateTime(2009, 11, 2, 0, 0, 0, DateTimeKind.Utc), time.NextTime(timeString)); // Monday morning...
     Assert.AreEqual(new DateTime(2009, 11, 4, 0, 0, 0, DateTimeKind.Utc), time.AddDays(3).NextTime(timeString)); // Wednesday morning...
     Assert.AreEqual(new DateTime(2009, 11, 6, 0, 0, 0, DateTimeKind.Utc), time.AddDays(5).NextTime(timeString)); // Friday morning...
 }
開發者ID:jcwmoore,項目名稱:athena,代碼行數:8,代碼來源:CronStringParserFixture.cs


注:本文中的System.DateTime.NextTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。