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

  • 相关阅读:
    每个android项目都应该使用的android 库
    解决android锁屏或解锁后activity重启的问题
    Git提交时提示‘The file will have its original line endings in your working directory’
    homestead虚拟机,通过npm下载依赖包和解决运行gulp报错问题 yarn出错问题
    免费获取验证码60秒倒计时
    html5表单验证(Bootstrap)
    jQuery 创建html
    HTML5中音频视频标签使用
    分享到朋友圈遮罩层
    TP细节总结1
  • 原文地址:https://www.cnblogs.com/soundcode/p/2112040.html
Copyright © 2011-2022 走看看