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#)两时间段每天是星期几,周几(时间段日历显示)的问题解决

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值