首页 > 代码库 > WPF 本周、本月、本季、本年的第一天与最后一天取法

WPF 本周、本月、本季、本年的第一天与最后一天取法

         lblWeekStart.Content = DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
          lblWeekEnd.Content = DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();


           lblMouthStart.Content = DateTime.Today.AddDays(-(DateTime.Today.Day) + 1).ToString("yyyy-MM-dd");
           lblMouthEnd.Content = DateTime.Today.AddMonths(1).AddDays(-(DateTime.Today.Day)).ToString("yyyy-MM-dd");//最后一天


            lblQuarterStart.Content = DateTime.Today.AddMonths(0 - (DateTime.Today.Month - 1) % 3).AddDays(1 - DateTime.Today.Day).ToString("yyyy-MM-dd"); 

            lblQuarterEnd.Content = DateTime.Today.AddMonths(0 - (DateTime.Today.Month - 1) % 3).AddDays(1 - DateTime.Today.Day).AddMonths(3).AddDays(-1).ToString("yyyy-MM-dd");   

            lblYearStart.Content = new DateTime(DateTime.Today.Year, 1, 1).ToString("yyyy-MM-dd");  

            lblYearEnd.Content = new DateTime(DateTime.Today.Year, 12, 31).ToString("yyyy-MM-dd"); 

 

说明:以lbl开头的为 Label 控件