本文整理汇总了C#中System.Globalization.Calendar.AddWeeks方法的典型用法代码示例。如果您正苦于以下问题:C# Calendar.AddWeeks方法的具体用法?C# Calendar.AddWeeks怎么用?C# Calendar.AddWeeks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.Calendar
的用法示例。
在下文中一共展示了Calendar.AddWeeks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOccurrences
private static IEnumerable<DateTime> GetOccurrences(DateInterval interval, DatePeriod period, Calendar calendar, DateTime start, DateTime end, bool skipWeekends = true)
{
var difference = DateSpan.GetDifference(interval, start, end)/period.Quantifier;
if (start.Kind == DateTimeKind.Utc)
{
start = start.ToLocalTime();
}
for (var i = 0; i < difference; i++)
{
switch (period.Frequency)
{
case DatePeriodFrequency.Seconds:
var seconds = calendar.AddSeconds(start, period.Quantifier * i);
yield return DeferOccurrenceFallingOnWeekend(calendar, seconds, skipWeekends);
break;
case DatePeriodFrequency.Minutes:
var minutes = calendar.AddMinutes(start, period.Quantifier * i);
yield return DeferOccurrenceFallingOnWeekend(calendar, minutes, skipWeekends);
break;
case DatePeriodFrequency.Hours:
var hours = calendar.AddHours(start, period.Quantifier * i);
yield return DeferOccurrenceFallingOnWeekend(calendar, hours, skipWeekends);
break;
case DatePeriodFrequency.Days:
var days = calendar.AddDays(start, period.Quantifier*i);
yield return DeferOccurrenceFallingOnWeekend(calendar, days, skipWeekends);
break;
case DatePeriodFrequency.Weeks:
var weeks = calendar.AddWeeks(start, period.Quantifier*i);
yield return DeferOccurrenceFallingOnWeekend(calendar, weeks, skipWeekends);
break;
case DatePeriodFrequency.Months:
var months = calendar.AddMonths(start, period.Quantifier*i);
yield return DeferOccurrenceFallingOnWeekend(calendar, months, skipWeekends);
break;
case DatePeriodFrequency.Years:
var years = calendar.AddYears(start, period.Quantifier*i);
yield return DeferOccurrenceFallingOnWeekend(calendar, years, skipWeekends);
break;
default:
throw new ArgumentException("Frequency");
}
}
}
示例2: GetFirstDayOfWeek
/// <summary>
/// Gets the first day of a week.
/// </summary>
/// <param name="year">The year.</param>
/// <param name="week">The week.</param>
/// <param name="calendar">The calendar.</param>
/// <param name="calendarWeekRule">The calendar week rule.</param>
/// <param name="firstDayOfWeek">The first day of week.</param>
/// <returns>The date of the first day in the week.</returns>
public static DateTime GetFirstDayOfWeek(
int year,
int week,
Calendar calendar = null,
CalendarWeekRule calendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
{
if (calendar == null)
calendar = CultureInfo.CurrentCulture.Calendar;
DateTime firstDay = new DateTime(year, 1, 7, calendar);
while (calendar.GetDayOfWeek(firstDay) != firstDayOfWeek || WeekNumber(firstDay, calendar, calendarWeekRule, firstDayOfWeek) % 52 > 1)
{
firstDay = calendar.AddDays(firstDay, -1);
}
// Add the week
return (week != 1) ? calendar.AddWeeks(firstDay, week - 1) : firstDay;
}