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


C# TimeSpan.AddMonths方法代码示例

本文整理汇总了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())));
		}
开发者ID:nakaneku,项目名称:Hearthstone-Deck-Tracker,代码行数:60,代码来源:DeckStatsControl.xaml.cs

示例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);
        }
开发者ID:ChuckFork,项目名称:hdt-plugin-statsconverter,代码行数:49,代码来源:StatsFilter.cs


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