• 日期周期计算


    方法一:

    protected void Page_Load(object sender, EventArgs e)
        {

            string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };

            string[] data = { "2015-03-15", "2015-03-16", "2015-03-17", "2015-03-18", "2015-03-19", "2015-03-20", "2015-03-21" };

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                int y = Convert.ToInt32(Convert.ToDateTime(data[i]).DayOfWeek.ToString("d"));
                Response.Write(y);
                Response.Write("</br>");

                //string week = Day[y].ToString();
                DateTime start = (Convert.ToDateTime(data[i])).AddDays(1 - y);
                DateTime end = (Convert.ToDateTime(data[i])).AddDays(6 - y);
                sb.Append("</br>");
                sb.Append(":" + data[i] + "  本周开始:" + start + "   本周结束" + end + "  ");
                sb.Append("</br>");
            }

            Response.Write(sb.ToString());
    }

    方法二:

    protected void Page_Load(object sender, EventArgs e)
    {

      StringBuilder sb = new StringBuilder();
            string[] data = getNowTime((DateTime.Now.DayOfWeek.ToString("d"))).Split(',');
            int num = Shove._Convert.StrToInt(DateTime.Now.DayOfWeek.ToString("d"), 0);
            List<string> wheres = new List<string>();
            for (int i = 0; i < Shove._Convert.StrToInt(data[0].ToString(), 0); i++)//前面
            {
                wheres.Add(DateTime.Now.AddDays(i - num).ToString("yyyy-MM-dd"));
            }
            //今天
            wheres.Add(DateTime.Now.ToString("yyyy-MM-dd"));
            //今天以后的
            for (int i = 0; i < Shove._Convert.StrToInt(data[1].ToString(), 0); i++)
            {
                wheres.Add(DateTime.Now.AddDays(i + 1).ToString("yyyy-MM-dd"));
            }


            for (int i = 0; i < wheres.Count; i++)
            {
                //wheres[i].ToString() + " 59:59:59";
            } 

    }

     public string getNowTime(string str)
        {
            string strTemp = "";
            switch (str)
            {
                case "0":
                    strTemp = "0,6";
                       break;
                case "1":
                       strTemp = "1,5";
                       break;
                case "2":
                       strTemp = "2,4";
                       break;
                case "3":
                       strTemp = "3,3";
                       break;
                case "4":
                       strTemp = "4,2";
                       break;
                case "5":
                       strTemp = "5,1";
                       break;
                case "6":
                       strTemp = "6,0";
                       break;
                 default:
                       strTemp = "0,6";
                       break;

            }
             return strTemp;
        }

  • 相关阅读:
    C# winForm webBrowser页面中js调用winForm类方法(转)
    Shader开发工具: PVRShaman
    创建压缩纹理的工具
    Andriod NDK编译的时候无法使用math.h的函数。
    mongodb自动关闭:页面文件太小,无法完成操作
    通读cheerio API
    How to skip to next iteration in jQuery.each() util?
    在javascript中substr和substring的区别是什么
    运行代码时报linker command failed with exit code 1 错误
    软件开发模式对比(瀑布、迭代、螺旋、敏捷)
  • 原文地址:https://www.cnblogs.com/lizihong/p/4346195.html
Copyright © 2020-2023  润新知