本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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
}
示例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();
}
示例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...
}