實現點擊按鈕更改周,並獲取本周,上周,下周對應的具體日期
借鑒了一些網上的方法
DateTime beginDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Monday, ); DateTime endDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Sunday, ); DateTime getWeekUpOfDate(DateTime dt, DayOfWeek weekday, wd1 = ( wd2 = ( wd2 == wd1 ? dt.AddDays( * Number) : dt.AddDays( * Number - wd2 + wd1);
更改周 按鈕事件 btnThisWeek_Click( beginDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Monday, ); endDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Sunday, ); btnLastWeek_Click( beginDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Monday, -); endDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Sunday, ); btnNextWeek_Click( beginDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Monday, ); endDate = getWeekUpOfDate(DateTime.Now, DayOfWeek.Sunday, );
DateTime beginTime = DateTime endTime = DateTime[] times = GetDateTime(beginTime, endTime); (times.Length > TextBox1.Text= times[].ToShortDateString(); TextBox2.Text = times[].ToShortDateString(); TextBox3.Text = times[].ToShortDateString(); TextBox4.Text = times[].ToShortDateString(); TextBox5.Text = times[].ToShortDateString(); TextBox6.Text = times[].ToShortDateString(); TextBox7.Text = times[].ToShortDateString(); }
List<DateTime> timeList = List<DateTime> (; beginTime <= endTime; beginTime = beginTime.AddDays()) DateTime[] times = }