C# 获取指定时间封装(今日、本周、任意时间)

 /// <summary>
        /// 获取选中时间
        /// </summary>
        private void GetSelectTime()
        {
            //今日
            if (rbToday.Checked == true)
            {
                dtpBeginTime.ReadOnly = true;
                dtpEndTime.ReadOnly = true;
                dtpBeginTime.Value = Convert.ToDateTime(DateTime.Now.ToString("D").ToString());
                dtpEndTime.Value = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("D").ToString()).AddSeconds(-1);
            }
            //本周
            else if (rbWeek.Checked == true)
            {
                dtpBeginTime.ReadOnly = true;
                dtpEndTime.ReadOnly = true;
                dtpBeginTime.Value = GetThisWeekMonday();
                dtpEndTime.Value = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("D").ToString()).AddSeconds(-1);
            }
            //自定义时间
            else if (rbCustomize.Checked == true)
            {
                dtpBeginTime.ReadOnly = false;
                dtpEndTime.ReadOnly = false;
            }

        }

 

posted @ 2020-06-28 20:00  博客YS  阅读(658)  评论(0编辑  收藏  举报