本文整理汇总了C#中DayOfWeek.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# DayOfWeek.GetValueOrDefault方法的具体用法?C# DayOfWeek.GetValueOrDefault怎么用?C# DayOfWeek.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DayOfWeek
的用法示例。
在下文中一共展示了DayOfWeek.GetValueOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EndOfWeek
/// <summary>
/// Returns the end of week from the supplied date
/// </summary>
public static DateTime EndOfWeek(this DateTime instance, DayOfWeek? on = null)
{
DayOfWeek day = on.GetValueOrDefault(DayOfWeek.Saturday);
int days = day - instance.DayOfWeek;
if (days < 0) days += 7;
days = days * -1;
return new DateTime(instance.Year, instance.Month, instance.Day, 23, 59, 59, 999).AddDays(days);
}
示例2: StartOfWeek
/// <summary>
/// Returns the start of week from the supplied date
/// </summary>
public static DateTime StartOfWeek(this DateTime instance, DayOfWeek? on = null)
{
DayOfWeek day = on.GetValueOrDefault(DayOfWeek.Sunday);
int days = instance.DayOfWeek - day;
if (days < 0) days += 7;
days = days * -1;
return new DateTime(instance.Year, instance.Month, instance.Day, 0, 0, 0, 0).AddDays(days);
}
示例3: GetWeekOfYearRuleKind
/// <summary>
/// <paramref name="weekRule"/>, <paramref name="firstDayOfWeek"/>에 해당하는 <see cref="WeekOfYearRuleKind"/>를 판단합니다.
/// </summary>
/// <param name="weekRule">한해의 첫주를 산정하는 규칙</param>
/// <param name="firstDayOfWeek">한주의 첫번째 요일</param>
public static WeekOfYearRuleKind GetWeekOfYearRuleKind(CalendarWeekRule? weekRule = null,
DayOfWeek? firstDayOfWeek = null) {
if(weekRule.GetValueOrDefault(DateTimeFormatInfo.CurrentInfo.CalendarWeekRule) == CalendarWeekRule.FirstFourDayWeek &&
firstDayOfWeek.GetValueOrDefault(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) == DayOfWeek.Monday)
return WeekOfYearRuleKind.Iso8601;
return WeekOfYearRuleKind.Calendar;
}