asp.net(c#)两时间段每天是星期几,周几(时间段日历显示)的问题解
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#)兩時間段每天是星期幾,周幾(時間段日歷顯示)的問題解決
總結(jié)
以上是生活随笔為你收集整理的asp.net(c#)两时间段每天是星期几,周几(时间段日历显示)的问题解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 背景-需要-需求规格
- 下一篇: 王企鹅和帝企鹅的区别(王企鹅)