DateTime Monday = Convert.ToDateTime(DateTime.Now.AddDays(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)).ToString("D").ToString()); DateTime Sunday = Mo ...
C#獲取當月第一天和最後一天 當月第一天0時0分0秒: DateTime.Now.AddDays(1 - DateTime.Now.Day).Date 當月最後一天23時59分59秒: DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1) C#獲取上個月第一天和最後一天 上個月第一天0時0分0秒: DateTime.Now.AddMonths(-1).Date.AddDays(1 - DateTime.Now.Day); 上個月最後一天23時59分59秒: DateTime.Parse(DateTime.Now.AddDays(1 - DateTime.Now.Day).ToShortDateString()).AddSeconds(-1).ToString(); 當天0時0分0秒: DateTime start = Convert.ToDateTime(DateTime.Now.ToString("D").ToString());
當天23時59分59秒: DateTime end = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("D").ToString()).AddSeconds(-1);
本周一0時0分0秒:
DateTime Monday = Convert.ToDateTime(DateTime.Now.AddDays(1 - Convert.ToInt32(DateTime.Now.DayOfWeek)).ToString("D").ToString());
本周日0時0分0秒:
DateTime Sunday = Monday.AddDays(7).AddSeconds(-1);