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

  • 相关阅读:
    zabbix 3.4自动化监控(6)
    zabbix 3.4 web监控(5)
    童年
    CSDN中快速转载别人文章
    10个提升效率的编程好习惯(转载)
    解决vscode中vim插件,不能使用Ctrl+c
    英语复习安排
    比勤奋更能拉开人生差距的,是成长型思维
    转载文章
    红宝书考研资料
  • 原文地址:https://www.cnblogs.com/soundcode/p/2112040.html
Copyright © 2011-2022 走看看