zoukankan      html  css  js  c++  java
  • 最近一周的日期选择设置

     private void radioGroup_SelectedIndexChanged(object sender, EventArgs e)
            {
                switch (radioGroup.SelectedIndex)
                {
                    //当天
                    case 0:
                        {
                            this.dateStart.DateTime = DateTime.Today;
                            this.dateEnd.DateTime = DateTime.Today;
                            break;
                        }
                    //本周
                    case 2:
                        {
                            int weeknow = Convert.ToInt32(System.DateTime.Now.DayOfWeek);
                            //星期日 获取weeknow为0 
                            weeknow = weeknow == 0 ? 7 : weeknow;
                            int daydiff = (-1) * weeknow + 1;
                            int dayadd = 7 - weeknow;
                            //本周第一天 
                            this.dateStart.DateTime = DateTime.Now.AddDays(daydiff);
                            //本周最后一天 
                            this.dateEnd.DateTime = DateTime.Now.AddDays(dayadd);
                            break;
                        }
                    //上周
                    case 4:
                        {
                            DateTime dt = DateTime.Now;  //当前时间
                            int dayOfWeek = Convert.ToInt32(dt.DayOfWeek.ToString("d"));
                            DateTime weekStart = dt.AddDays(1 - ((dayOfWeek == 0) ? 7 : dayOfWeek));   //本周周一
                            DateTime weekEnd = weekStart.AddDays(6);  //本周周日
                            this.dateStart.DateTime = weekStart.AddDays(-7);  //上周周一
                            this.dateEnd.DateTime = weekEnd.AddDays(-7);  //上周周日
                            break;
                        }
                    //本月
                    case 1:
                        {
                            this.dateStart.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                            this.dateEnd.DateTime = this.dateStart.DateTime.AddMonths(1).AddDays(-1);
                            break;
                        }
                    //上月
                    case 3:
                        {
                            DateTime lastMonth = DateTime.Now.AddMonths(-1);
                            this.dateStart.DateTime = lastMonth.AddDays(1 - lastMonth.Day);
                            this.dateEnd.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1);
                            break;
                        }
                    //本年
                    case 5:
                        {
                            this.dateStart.DateTime = new DateTime(DateTime.Now.Year, 1, 1);
                            this.dateEnd.DateTime = new DateTime(DateTime.Now.Year, 12, 31);
                            break;
                        }
                }
                //this.GetQuery();
            }

    效果 图

  • 相关阅读:
    【故障处理】ORA-12162: TNS:net service name is incorrectly specified (转)
    android studio 编程中用到的快捷键
    java时间格式串
    android Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.
    linux安装vmware
    x1c 2017 安装mint18的坑——grub2
    x1c2017 8G版 win linux的取舍纠结记录
    python的try finally (还真不简单)
    kafka+docker+python
    json文件不能有注释
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/6274779.html
Copyright © 2011-2022 走看看