我想检查一下,如果在webcalendar元素中的渲染日是X-mas Eve或1月1日或一年中的另一个日期,如果是这样,那么日期的颜色会有所不同.
因此,如果呈现的日期是5月的第三个星期一,则将其换色.如果它是X-mas前夕,用不同的颜色等等.
到目前为止,所有香港专业教育学院都发现了如何将这一天提取到特定日期.但我想做相反的事情.有没有人这样做,可以提供一些提示?
你不是很清楚你的意思是"尽管有点相反",但是:
static IsThirdMondayInMay(DateTime date)
{
// The first X in a month is always in the range [1, 8)
// The second X in a month is always in the range [8, 15)
// The third X in a month is always in the range [15, 22)
return date.Month == 5 && date.DayOfWeek == DayOfWeek.Monday &&
date.Day >= 15 && date.Day < 22;
}
static IsChristmasEve(DateTime date)
{
return date.Month == 12 && date.Day == 24;
}
Run Code Online (Sandbox Code Playgroud)
或者更普遍的是最后一个:
static MonthDayMatches(DateTime date, int month, int day)
{
return date.Month == month && date.Day == day;
}
Run Code Online (Sandbox Code Playgroud)
然后:
bool christmasEve = MonthDayMatches(date, 12, 24);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
417 次 |
| 最近记录: |