• 根据时段改变时间段


            /// <summary>
            /// 根据时段改变时间段
            /// </summary>
            /// <param name="timeIntervalValue">时段值</param>
            /// <param name="dtpStartTime">起始时间控件</param>
            /// <param name="dtpEndTime">结束时间控件</param>
            protected void ChangeTimeRangeByTimeInterval(string timeIntervalValue, DateTimePicker dtpStartTime, DateTimePicker dtpEndTime)
            {
                DateTime dateTimeTotay = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
                DateTime tempDate;
                switch (timeIntervalValue)
                {
                    case "0":
                        // 今天
                        dtpStartTime.Value = dateTimeTotay;
                        dtpEndTime.Value = dateTimeTotay.AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "1":
                        // 昨天
                        tempDate = dateTimeTotay.AddDays(-1);
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = tempDate.AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "2":
                        // 前天
                        tempDate = dateTimeTotay.AddDays(-2);
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = tempDate.AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "3":
                        // 本周
                        int temp = (int)dateTimeTotay.DayOfWeek - 1;
                        int days = temp == -1 ? 6 : temp;
                        dtpStartTime.Value = dateTimeTotay.AddDays(-days);
                        dtpEndTime.Value = dateTimeTotay.AddDays(6 - days).AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "4":
                        // 上周
                        temp = (int)dateTimeTotay.DayOfWeek - 1;
                        days = temp == -1 ? 6 : temp;
                        dtpStartTime.Value = dateTimeTotay.AddDays(-days - 7);
                        dtpEndTime.Value = dateTimeTotay.AddDays(-1 - days).AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "5":
                        // 本月
                        tempDate = Convert.ToDateTime(dateTimeTotay.ToString("yyyy-MM-01 00:00:00"));
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = tempDate.AddMonths(1).AddDays(-1).AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "6":
                        // 上月
                        tempDate = Convert.ToDateTime(dateTimeTotay.AddMonths(-1).ToString("yyyy-MM-01 00:00:00"));
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = tempDate.AddMonths(1).AddDays(-1).AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "7":
                        // 今年
                        tempDate = Convert.ToDateTime(dateTimeTotay.ToString("yyyy-01-01 00:00:00"));
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = tempDate.AddYears(1).AddDays(-1).AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "8":
                        // 去年
                        tempDate = Convert.ToDateTime(dateTimeTotay.AddYears(-1).ToString("yyyy-01-01 00:00:00"));
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = tempDate.AddYears(1).AddDays(-1).AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "9":
                        // 近七天
                        tempDate = dateTimeTotay.AddDays(-6);
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = dateTimeTotay.AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "10":
                        // 近30天
                        tempDate = dateTimeTotay.AddDays(-29);
                        dtpStartTime.Value = tempDate;
                        dtpEndTime.Value = dateTimeTotay.AddDays(1).AddMilliseconds(-1.0);
                        break;
                    case "11":
                        //全部时段
                        dtpStartTime.Value = Convert.ToDateTime("1971-01-01 00:00:00");
                        dtpEndTime.Value = dateTimeTotay.AddDays(1).AddMilliseconds(-1.0);
                        break;
                }
            }
  • 相关阅读:
    多层级makefile
    vscode常用快捷键
    unix socket接口
    以太网复习
    shell脚本算术运算
    1185: 零起点学算法92——单词数(C)
    1183: 零起点学算法90——海选女主角(C语言)
    1181: 零起点学算法88——偶数求和(C语言)
    1144: 零起点学算法51——数组中删数(C语言)
    列主元消去法&全主元消去法——Java实现
  • 原文地址:https://www.cnblogs.com/yuwuji/p/6598541.html
Copyright © 2020-2023  润新知