asp.net(c#)两时间段每天是星期几,周几(时间段日历显示)的问题解决
string temp="<table width=\"560\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"dddddd\" align=center height=\"100\"> ";
temp=temp+"<tr align=\"center\" bgcolor=\"#CCCCCC\"> ";
temp=temp+"<td width =\"14%\" height=\"19\"> 日</td> ";
temp=temp+"<td width=\"14%\"> 一</td> ";
temp=temp+"<td width=\"14%\"> 二</td> ";
temp=temp+"<td width=\"14%\"> 三</td> ";
temp=temp+"<td width=\"14%\"> 四</td> ";
temp=temp+"<td width=\"14%\"> 五</td> ";
temp=temp+"<td width=\"14%\"> 六</td> ";
temp=temp+"</tr> ";
temp = temp + "<tr align=center bgcolor=ffffff height=19> ";
DateTime dt1 = System.Convert.ToDateTime("2009-7-2");
DateTime dt2 = System.Convert.ToDateTime("2009-8-20");
TimeSpan ts = dt2 -dt1 ;
int countday = (int)ts.TotalDays;
int maxi = countday;
int i=1 ;
while (dt1 < dt2)
{
if (i == 1)
{
int t = xingqi(dt1.ToString("yyyy-MM-dd").ToString()); //开始的第一天位置
while (i < t+1)
{
temp = temp + "<td align=center></td>";
i++;
}
}
temp = temp + "<td align=center>" + dt1.ToString("yyyy-MM-dd").ToString() + "</td>";
if (i % 7 == 0)
{
temp = temp + "</tr><tr align=center bgcolor=ffffff height=19>";
}
i = i + 1;
dt1 = dt1.AddDays(1);
}
temp = temp + "</table>";
Response.Write(temp);
}
public static int xingqi(string d) //判断星期几
{
int reslut = 0; //周日
string xq = Convert.ToDateTime(d).DayOfWeek.ToString();
switch (xq)
{
case "Monday": //星期一;
reslut = 1;
break;
case "Tuesday":
reslut = 2;
break;
case "Wednesday":
reslut = 3;
break;
case "Thursday":
reslut = 4;
break;
case "Friday":
reslut = 5;
break;
case "Saturday": //星期六;
reslut = 6;
break;
case "Sunday":
reslut = 0;
break;
default:
reslut = 0;
break;
}
return reslut;
}
asp.net(c#)两时间段每天是星期几,周几(时间段日历显示)的问题解决
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2011/07/20/2112040.html,如需转载请自行联系原作者