我想检查一下,如果在webcalendar元素中呈现的日期是X-mas Eve或1月1日或一年中的另一个日期,如果是这样,那么日期的颜色会有所不同。
因此,如果呈现的日期是5月的第三个星期一,请将其换色。如果它是X-mas前夕,用不同的颜色等等。
到目前为止,所有香港专业教育学院都发现了如何将这一天提取到特定日期。但我想做相反的事情。有没有人这样做,可以提供一些提示?答案 0 :(得分:5)
“你有点反对”并不清楚你的意思,但是:
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;
}
或者更普遍地说是最后一次:
static MonthDayMatches(DateTime date, int month, int day)
{
return date.Month == month && date.Day == day;
}
然后:
bool christmasEve = MonthDayMatches(date, 12, 24);
答案 1 :(得分:2)
我假设您使用的是ASP.NET Calendar
control。然后使用DayRender
event。这个参数Day
的属性Date
是DateTime
。现在,您可以使用此日期来决定是否是特殊日期。
void DayRender(Object source, DayRenderEventArgs e)
{
DateTime date = e.Day.Date; // here it is
if(IsSpecialDay(date)) // your method to determine if a given date is a "special"-date
e.Cell.BackColor = System.Drawing.Color.Gold; // or use the Style property to use CSS
}