本文整理汇总了C#中System.DateTime.Next方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.Next方法的具体用法?C# DateTime.Next怎么用?C# DateTime.Next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.Next方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldGiveSameDayWhenWeekdayMatches
public void ShouldGiveSameDayWhenWeekdayMatches()
{
DateTime saturday = new DateTime(2012, 04, 21);
DateTime nextSaturday = saturday.Next(DayOfWeek.Saturday);
Assert.That(nextSaturday, Is.EqualTo(saturday));
}
示例2: GroupNotes
public GroupNotes()
{
InitializeComponent();
admin = false;
String query = "select ClientNum, ClientName from ClientInfo where IntakeDate not like '0001-01-01%' and ExitDate like '0001-01-01%'";
clients = database.GetTable(query);
editingDay = DateTime.Now;
lastDayOfWeek = editingDay.Next(DayOfWeek.Sunday);
firstDayOfWeek = editingDay.StartOfWeek(DayOfWeek.Monday);
dayOfWeek = editingDay.DayOfWeek.ToString();
WeekOf_Label.Text = "Week of " + firstDayOfWeek.ToString("MM/dd") + " through " + lastDayOfWeek.ToString("MM/dd");
updateClientList();
clientList.SetSelected(0, true);
newPDFPath = "/clientfiles/groupnotes/" + loadClientID + "/"; // C:\\Users/Darryl/SparkleShare/WestSlopeSecure
newFile = newPDFPath + firstDayOfWeek.ToString("MM-dd-yyyy") + ".pdf";
templatePathFromOld = newPDFPath + firstDayOfWeek.ToString("MM-dd-yyyy") + "-old.pdf";
// Wipe out shit files.
if (Directory.Exists(newPDFPath))
{
foreach (var file in Directory.EnumerateFiles(newPDFPath, "*-old.pdf", SearchOption.TopDirectoryOnly))
File.Delete(file);
}
processPdfGen();
DaySelection.SelectedIndex = ((int)(editingDay.DayOfWeek) + 6) % 7;
}
示例3: ShouldGiveNextWeekday
public void ShouldGiveNextWeekday()
{
DateTime saturday = new DateTime(2012, 04, 21);
DateTime nextMonday = saturday.Next(DayOfWeek.Monday);
Assert.That(nextMonday, Is.EqualTo(saturday.AddDays(2)));
}
示例4: ScheduleRoundDates
public IEnumerable<DateTime> ScheduleRoundDates(DateTime startDate, DateTime endDate, DayOfWeek dayOfWeek, int frequency, params int[] stageRoundCounts)
{
int roundCount = stageRoundCounts.Sum();
int stageCount = stageRoundCounts.Length;
var dates = new List<DateTime>();
DateTime date = startDate.Next(dayOfWeek);
int weeks = (endDate - date).Days / 7 + 1;
int breakLength = weeks - frequency * roundCount;
int halfStageIndex = CalculateHalfStageIndex(stageRoundCounts, roundCount, stageCount);
for (int i = 0; i < stageCount; i++)
{
var roundDates = new DateTime[stageRoundCounts[i]];
for (int j = 0; j < roundDates.Length; j++)
{
roundDates[j] = date;
date = date.AddDays(checked(7 * frequency)).Date;
}
dates.AddRange(roundDates);
if (i == halfStageIndex)
{
date = date.AddDays(7 * breakLength).Date;
}
}
return dates;
}
示例5: UTCDateFromYearMonthWeekDay
private static DateTime UTCDateFromYearMonthWeekDay(int year, int month, int week, int day)
{
var date = new DateTime (year, month, 1).ToUniversalTime ();
var dayOfWeekWanted = (DayOfWeek)Enum.ToObject (typeof(DayOfWeek), day);
var beginningDay = (int) date.DayOfWeek;
if (beginningDay < day)
date = date.Next (dayOfWeekWanted);
else if (beginningDay > day) {
var previous = date.Previous (dayOfWeekWanted);
if (previous.Month == month)
date = previous;
else
date = date.Next (dayOfWeekWanted);
}
var daysToAdd = (week - 1) * 7;
return date.AddDays (daysToAdd);
}
示例6: LeaguePlayOffsSeason
public LeaguePlayOffsSeason(LeaguePlayOffs playOffs, DateTime startDate, DateTime endDate, IEnumerable<TeamPair> teamPairs)
: base(playOffs, startDate, endDate)
{
DateTime firstLegDate = startDate.Next(playOffs.DayOfWeek);
DateTime secondLegDate = firstLegDate.AddDays(7);
Ties = teamPairs.Select(p => new Tie(firstLegDate, secondLegDate, p.Team1, p.Team2)).ToList();
var teams = Enumerable.Union(teamPairs.Select(p => p.Team1).ToArray(), teamPairs.Select(p => p.Team2).ToArray()).ToList();
AddTeams(teams);
}
示例7: NextDate_Tests
public void NextDate_Tests()
{
DateTime thursdayFourteenthFebruary2008 = new DateTime(2008, 2, 14);
Assert.AreEqual(new DateTime(2008, 2, 18), thursdayFourteenthFebruary2008.Next(DayOfWeek.Monday));
Assert.AreEqual(new DateTime(2008, 2, 21), thursdayFourteenthFebruary2008.Next(DayOfWeek.Thursday));
Assert.AreEqual(new DateTime(2008, 2, 15), thursdayFourteenthFebruary2008.Next(DayOfWeek.Friday));
Assert.AreEqual(new DateTime(2008, 2, 18), thursdayFourteenthFebruary2008.Next(DayOfWeek.Monday, true));
Assert.AreEqual(new DateTime(2008, 2, 15), thursdayFourteenthFebruary2008.Next(DayOfWeek.Friday, true));
Assert.AreEqual(new DateTime(2008, 2, 14), thursdayFourteenthFebruary2008.Next(DayOfWeek.Thursday, true));
}
示例8: CheckNextLastIndicator
/// <summary>
/// next week
/// last month
/// next june
/// last monday
/// </summary>
/// <param name="dateString"></param>
/// <param name="dateBase"></param>
/// <returns></returns>
private DateTime? CheckNextLastIndicator(string dateString, DateTime dateBase)
{
Match match = nextLastUnit.Match(dateString);
if (match.Success)
{
bool isNext = match.Groups[1].Value.Equals("next");
string unit = match.Groups[2].Value;
if (StringIsDayOfTheWeek(unit))
{
return ParseRelative(dateBase, dateString.Substring(5)).AddWeeks(isNext ? 1 : -1);
}
if (unit.Equals("month"))
{
return isNext ? dateBase.Next(DateUnit.Month) : dateBase.Last(DateUnit.Month);
}
if (allMonthNames.Contains(unit, StringComparer.CurrentCultureIgnoreCase))
{
return ParseRelative(dateBase, unit).AddYears(1);
}
}
return null;
}
示例9: CheckEntireStringIsDay
/// <summary>
/// friday
/// </summary>
/// <param name="dateString"></param>
/// <param name="dateBase"></param>
/// <returns></returns>
private DateTime? CheckEntireStringIsDay(string dateString, DateTime dateBase)
{
if (StringIsDayOfTheWeek(dateString))
{
return dateBase.Next(StringToDayOfWeek(dateString));
}
return null;
}
示例10: NextLast
public void NextLast()
{
var date = new DateTime(2015, 8, 7).Date;
Assert.AreEqual(new DateTime(2015, 8, 10), date.Next(DayOfWeek.Monday));
Assert.AreEqual(new DateTime(2015, 8, 14), date.Next(DayOfWeek.Friday));
Assert.AreEqual(new DateTime(2015, 8, 9), date.Next(DayOfWeek.Sunday));
Assert.AreEqual(new DateTime(2015, 8, 15), date.Next(DayOfWeek.Saturday));
Assert.AreEqual(new DateTime(2015, 8, 3), date.Last(DayOfWeek.Monday));
Assert.AreEqual(new DateTime(2015, 7, 31), date.Last(DayOfWeek.Friday));
Assert.AreEqual(new DateTime(2015, 8, 2), date.Last(DayOfWeek.Sunday));
Assert.AreEqual(new DateTime(2015, 8, 1), date.Last(DayOfWeek.Saturday));
}
示例11: GetNthWeekofMonth
/// <summary>
/// Get a DateTime that represents the provided day of the week in the provided numerical week of the provided date. Example: 2nd Thursday.
/// </summary>
/// <param name="date">The date</param>
/// <param name="nthWeek">The numerical week to get the DateTime in</param>
/// <param name="dayOfWeek">The day of the week you want the DateTime to be in</param>
/// <returns></returns>
public static DateTime GetNthWeekofMonth(DateTime date, int nthWeek, DayOfWeek dayOfWeek)
{
return date.Next(dayOfWeek).AddDays((nthWeek - 1) * 7);
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
// if (Vars.DevEnv)
// System.Threading.Thread.Sleep(new Random().Next(2000));
if (Request.QueryString["type"] == "calendar")
{
bool freeGuestlist = Request.QueryString["freeGuestlist"] == null || Request.QueryString["freeGuestlist"].Length == 0 || Request.QueryString["freeGuestlist"] == "0" ? false : true;
Brand brand = Request.QueryString["brandk"] == null || Request.QueryString["brandk"].Length == 0 || Request.QueryString["brandk"] == "0" ? null : new Brand(int.Parse(Request.QueryString["brandk"]));
Place place = Request.QueryString["placek"] == null || Request.QueryString["placek"].Length == 0 || Request.QueryString["placek"] == "0" ? null : new Place(int.Parse(Request.QueryString["placek"]));
Venue venue = Request.QueryString["venuek"] == null || Request.QueryString["venuek"].Length == 0 || Request.QueryString["venuek"] == "0" || Request.QueryString["venuek"] == "1" ? null : new Venue(int.Parse(Request.QueryString["venuek"]));
int key = Request.QueryString["key"] == null || Request.QueryString["key"].Length == 0 || Request.QueryString["key"] == "0" ? 0 : int.Parse(Request.QueryString["key"]);
MusicType music = Request.QueryString["musictypek"] == null || Request.QueryString["musictypek"].Length == 0 || Request.QueryString["musictypek"] == "0" ? null : new MusicType(int.Parse(Request.QueryString["musictypek"]));
bool me = Request.QueryString["me"] != null && Request.QueryString["me"] == "1";
bool addGalleryButton = Request.QueryString["addgallery"] != null && Request.QueryString["addgallery"] == "1";
bool allVenues = Request.QueryString["venuek"] != null && Request.QueryString["venuek"] == "1";
DateTime date = new DateTime(
int.Parse(Request.QueryString["date"].Substring(0, 4)),
int.Parse(Request.QueryString["date"].Substring(4, 2)),
int.Parse(Request.QueryString["date"].Substring(6, 2)) > 0 ? int.Parse(Request.QueryString["date"].Substring(6, 2)) : 1 );
//if (date == DateTime.Today)
// System.Threading.Thread.Sleep(1000);
DateTime from = date.Previous(DayOfWeek.Monday, true);
DateTime to = date.Next(DayOfWeek.Sunday, true);
Event.EventsForDisplay events = new Event.EventsForDisplay();
events.IgnoreMusicType = true;
if (me)
{
events.AttendedUsrK = Usr.Current.K;
}
else if (brand != null)
{
events.BrandK = brand.K;
}
else if (venue != null)
{
events.VenueK = venue.K;
}
else if (place != null && music != null)
{
events.PlaceK = place.K;
events.MusicTypeK = music.K;
}
else if (place != null && freeGuestlist)
{
events.PlaceK = place.K;
events.FreeGuestlist = freeGuestlist;
}
else if (key > 0)
{
}
else
throw new Exception();
EventSet es;
if (key == 0)
es = events.GetEventsBetweenDates(from, to);
else
es = new EventSet(new Query(new Q(Event.Columns.K, key)));
CustomControls.DsiCalendar calendar = new Spotted.CustomControls.DsiCalendar();
calendar.AllEvents = es;
calendar.Month = date.Month;
calendar.ShowCountryFriendlyName = !(events.FilterByCountry || events.FilterByPlace || events.FilterByVenue);
calendar.ShowPlace = !(events.FilterByPlace || events.FilterByVenue);
calendar.ShowVenue = !events.FilterByVenue;
calendar.ShowAddGalleryButton = addGalleryButton;
calendar.Tickets = true;
calendar.StartDate = from;
calendar.EndDate = to;
Out.Controls.Add(calendar);
}
else
{
sb.AppendLine("{");
if (Request.QueryString["type"] == "music")
{
#region Music types
Query q = new Query();
q.QueryCondition = new Q(MusicType.Columns.K, QueryOperator.NotEqualTo, 1);
q.Columns = new ColumnSet(MusicType.Columns.Name, MusicType.Columns.ParentK, MusicType.Columns.K);
q.OrderBy = new OrderBy(MusicType.Columns.Order, OrderBy.OrderDirection.Ascending);
q.CacheDuration = TimeSpan.FromDays(1);
MusicTypeSet mts = new MusicTypeSet(q);
append(sb, "Select your music...", "0");
append(sb, "", "");
foreach (MusicType mt in mts)
{
append(sb, (mt.ParentK == 1 ? "" : "... ") + mt.Name, mt.K.ToString());
//.........这里部分代码省略.........
示例13: Next_ReturnsNextFridayProperly
public void Next_ReturnsNextFridayProperly()
{
var friday = new DateTime(2009, 7, 10, 1, 0, 0, 0, DateTimeKind.Local);
var reallyNextFriday = new DateTime(2009, 7, 17, 1, 0, 0, 0, DateTimeKind.Local);
var nextFriday = friday.Next(DayOfWeek.Friday);
DateAssert.AreEqual(reallyNextFriday, nextFriday);
}
示例14: BasicTests
public void BasicTests()
{
var now = DateTime.Now;
DateAssert.AreEqual(new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999, DateTimeKind.Local), DateTime.Now.EndOfDay(), " End of the day wrong");
DateAssert.AreEqual(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0, DateTimeKind.Local), DateTime.Now.BeginningOfDay(), "Start of the day wrong");
var firstBirthDay = new DateTime(1977, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);
DateAssert.AreEqual(firstBirthDay + new TimeSpan(1, 0, 5, 0, 0), firstBirthDay + 1.Days() + 5.Minutes());
DateAssert.AreEqual(now + TimeSpan.FromDays(1), now.NextDay());
DateAssert.AreEqual(now - TimeSpan.FromDays(1), now.PreviousDay());
DateAssert.AreEqual(now + TimeSpan.FromDays(7), now.WeekAfter());
DateAssert.AreEqual(now - TimeSpan.FromDays(7), now.WeekEarlier());
Assert.AreEqual(new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local), new DateTime(2008, 12, 31, 0, 0, 0, DateTimeKind.Local).Add(1.Days()));
Assert.AreEqual(new DateTime(2009, 1, 2, 0, 0, 0, 0, DateTimeKind.Local), new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local).Add(1.Days()));
var sampleDate = new DateTime(2009, 1, 1, 13, 0, 0, 0, DateTimeKind.Local);
DateAssert.AreEqual(new DateTime(2009, 1, 1, 12, 0, 0, 0, DateTimeKind.Local), sampleDate.Noon());
DateAssert.AreEqual(new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local), 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 DateTime(2008, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);
DateAssert.AreEqual(3.Days().Since(sampleDate), sampleDate + 3.Days());
var saturday = new DateTime(2008, 10, 25, 12, 0, 0, DateTimeKind.Local);
DateAssert.AreEqual(new DateTime(2008, 11, 1, 12, 0, 0, DateTimeKind.Local), saturday.Next(DayOfWeek.Saturday));
DateAssert.AreEqual(new DateTime(2008, 10, 18, 12, 0, 0, DateTimeKind.Local), saturday.Previous(DayOfWeek.Saturday));
// ReSharper disable UnusedVariable
var nextWeek = DateTime.Now + 1.Weeks();
var tomorrow = DateTime.Now + 1.Days();
var yesterday = DateTime.Now - 1.Days();
var changedHourTo14H = DateTime.Now.SetHour(14);
var todayNoon = DateTime.Now.Noon();
var tomorrowNoon = DateTime.Now.NextDay().Noon();
var fiveDaysAgo = 5.Days().Ago();
var twoDaysFromNow = 2.Days().FromNow();
var nextYearSameDateAsTodayNoon = 1.Years().FromNow().Noon();
var twoWeeksFromNow = 2.Weeks().FromNow();
// ReSharper restore UnusedVariable
}