.net中获取周一、月初、月末、年初、年末
2013-05-28 07:13
288 查看
DateTime startWeek = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))); //本周周一
DateTime endWeek = startWeek.AddDays(6); //本周周日
DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初
DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末
//DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); //本月月末
DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day); //本季度初
DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1); //本季度末
DateTime startYear = new DateTime(dt.Year, 1, 1); //本年年初
DateTime endYear = new DateTime(dt.Year, 12, 31); //本年年末
DateTime endWeek = startWeek.AddDays(6); //本周周日
DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初
DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末
//DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); //本月月末
DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day); //本季度初
DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1); //本季度末
DateTime startYear = new DateTime(dt.Year, 1, 1); //本年年初
DateTime endYear = new DateTime(dt.Year, 12, 31); //本年年末
相关文章推荐
- 【Oracle】TRUNC:获取去年年初和年末,获取月初和月末;
- DateTime - 求本月月末,本月月初,本周周日,本周周一,本季度末,本年年初,本年年末
- C#获取周一周日月末月初度末度初年初年末
- 用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间
- Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间
- C#获取周一、周日的日期,月初,月末,季度第一天,季度最后一天
- 获取指定日期的常用前后节点(月初月末周一周末等等)
- 用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间
- 取得当前日期相对应的月初,月末,季初,季末,年初,年末
- 获取指定日期的常用前后节点(月初月末周一周末等等)
- 此类用于取得当前日期相对应的月初,月末,季初,季末,年初,年末,返回值均为String字符串
- 计算月初和月末,年初和年末的日期
- C# 和SQL 计算时间:周一,周日,月初,月末,季初,季末...
- c# 根据当前时间获取,本周,本月,本季度,月初,月末,各个时间段(转但是都是使用过)
- 转:c# 根据当前时间获取,本周,本月,本季度,月初,月末,各个时间段
- c# 根据当前时间获取,本周,本月,本季度,月初,月末,各个时间段
- php获取当前月与上个月月初及月末时间戳的方法
- Js和Java,获取当前日期的前、后几天,考虑月初、月末
- php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳
- c# 根据当前时间获取,本周,本月,本季度,月初,月末,各个时间段