本文整理匯總了C#中System.TimeSpan.AddMonths方法的典型用法代碼示例。如果您正苦於以下問題:C# TimeSpan.AddMonths方法的具體用法?C# TimeSpan.AddMonths怎麽用?C# TimeSpan.AddMonths使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.AddMonths方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FilterGames
private IEnumerable<GameStats> FilterGames(IEnumerable<GameStats> games)
{
var selectedGameMode = (GameMode)ComboboxGameMode.SelectedItem;
var noteFilter = TextboxNoteFilter.Text;
var comboboxString = (TimeFrame)ComboboxTime.SelectedItem;
var endTime = DateTime.Today + new TimeSpan(0, 23, 59, 59, 999);
var startTime = DateTime.Today;
switch(comboboxString)
{
case Today:
endTime = DateTime.Now;
break;
case Yesterday:
startTime -= new TimeSpan(1, 0, 0, 0);
endTime -= new TimeSpan(1, 0, 0, 0);
break;
case Last24Hours:
startTime = DateTime.Now - new TimeSpan(1, 0, 0, 0);
endTime = DateTime.Now;
break;
case ThisWeek:
startTime -= new TimeSpan(((int)(startTime.DayOfWeek) - 1), 0, 0, 0);
break;
case PreviousWeek:
startTime -= new TimeSpan(7 + ((int)(startTime.DayOfWeek) - 1), 0, 0, 0);
endTime -= new TimeSpan(((int)(endTime.DayOfWeek)), 0, 0, 0);
break;
case Last7Days:
startTime -= new TimeSpan(7, 0, 0, 0);
break;
case ThisMonth:
startTime -= new TimeSpan(startTime.Day - 1, 0, 0, 0);
break;
case PreviousMonth:
startTime -= new TimeSpan(startTime.Day - 1 + DateTime.DaysInMonth(startTime.AddMonths(-1).Year, startTime.AddMonths(-1).Month), 0,
0, 0);
endTime -= new TimeSpan(endTime.Day, 0, 0, 0);
break;
case ThisYear:
startTime -= new TimeSpan(startTime.DayOfYear - 1, 0, 0, 0);
break;
case PreviousYear:
startTime -= new TimeSpan(startTime.DayOfYear - 1 + (DateTime.IsLeapYear(startTime.Year) ? 366 : 365), 0, 0, 0);
endTime -= new TimeSpan(startTime.DayOfYear, 0, 0, 0);
break;
case AllTime:
startTime = new DateTime();
break;
}
return
games.Where(
g =>
(g.GameMode == selectedGameMode || selectedGameMode == GameMode.All) && g.StartTime >= startTime
&& g.StartTime <= endTime
&& (g.Note == null && noteFilter == string.Empty
|| g.Note != null && g.Note.ToLowerInvariant().Contains(noteFilter.ToLowerInvariant())));
}
示例2: GetFilterTimes
private Tuple<DateTime, DateTime> GetFilterTimes(TimeFrame tf)
{
var startTime = DateTime.Today;
var endTime = DateTime.Today + new TimeSpan(0, 23, 59, 59, 999);
switch (TimeFrame)
{
case TimeFrame.Today:
endTime = DateTime.Now;
break;
case TimeFrame.Yesterday:
startTime -= new TimeSpan(1, 0, 0, 0);
endTime -= new TimeSpan(1, 0, 0, 0);
break;
case TimeFrame.Last24Hours:
startTime = DateTime.Now - new TimeSpan(1, 0, 0, 0);
endTime = DateTime.Now;
break;
case TimeFrame.ThisWeek:
startTime -= new TimeSpan(((int)(startTime.DayOfWeek) - 1), 0, 0, 0);
break;
case TimeFrame.PreviousWeek:
startTime -= new TimeSpan(7 + ((int)(startTime.DayOfWeek) - 1), 0, 0, 0);
endTime -= new TimeSpan(((int)(endTime.DayOfWeek)), 0, 0, 0);
break;
case TimeFrame.Last7Days:
startTime -= new TimeSpan(7, 0, 0, 0);
break;
case TimeFrame.ThisMonth:
startTime -= new TimeSpan(startTime.Day - 1, 0, 0, 0);
break;
case TimeFrame.PreviousMonth:
startTime -= new TimeSpan(startTime.Day - 1 + DateTime.DaysInMonth(startTime.AddMonths(-1).Year, startTime.AddMonths(-1).Month), 0, 0, 0);
endTime -= new TimeSpan(endTime.Day, 0, 0, 0);
break;
case TimeFrame.ThisYear:
startTime -= new TimeSpan(startTime.DayOfYear - 1, 0, 0, 0);
break;
case TimeFrame.PreviousYear:
startTime -= new TimeSpan(startTime.DayOfYear - 1 + (DateTime.IsLeapYear(startTime.Year) ? 366 : 365), 0, 0, 0);
endTime -= new TimeSpan(startTime.DayOfYear, 0, 0, 0);
break;
default:
startTime = new DateTime();
break;
}
return new Tuple<DateTime, DateTime>(startTime, endTime);
}