c# 获取 本周、本月、本季度、本年 的开始时间或结束时间
2015-02-04 10:34
666 查看
#region 获取 本周、本月、本季度、本年 的开始时间或结束时间 /// <summary> /// 获取结束时间 /// </summary> /// <param name="TimeType">Week、Month、Season、Year</param> /// <param name="now"></param> /// <returns></returns> public static DateTime? GetTimeStartByType(string TimeType, DateTime now) { switch (TimeType) { case "Week": return now.AddDays(-(int)now.DayOfWeek + 1); case "Month": return now.AddDays(-now.Day + 1); case "Season": var time = now.AddMonths(0 - ((now.Month - 1) % 3)); return time.AddDays(-time.Day + 1); case "Year": return now.AddDays(-now.DayOfYear + 1); default: return null; } } /// <summary> /// 获取结束时间 /// </summary> /// <param name="TimeType">Week、Month、Season、Year</param> /// <param name="now"></param> /// <returns></returns> public static DateTime? GetTimeEndByType(string TimeType, DateTime now) { switch (TimeType) { case "Week": return now.AddDays(7 - (int)now.DayOfWeek); case "Month": return now.AddMonths(1).AddDays(-now.AddMonths(1).Day + 1).AddDays(-1); case "Season": var time = now.AddMonths((3 - ((now.Month - 1) % 3) - 1)); return time.AddMonths(1).AddDays(-time.AddMonths(1).Day + 1).AddDays(-1); case "Year": var time2 = now.AddYears(1); return time2.AddDays(-time2.DayOfYear); default : return null; } } #endregion
相关文章推荐
- C#获取本周、上周、本月、上月、本季度、上季度、本年、上一年起始时间和结束时间
- Java获取当天、本周、本月、本季度、本年等 开始及结束时间
- Java获取当天、本周、本月、本季度、本年等 开始及结束时间
- java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间(总结一下,以后直接拿来用)
- java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间
- java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间
- java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间
- C# 根据当前时间获取本周、本月、本季度、本年的始末日期
- Java写的获取日期工具类(今天、昨天、本周、上周、本月、上月、本年及特定时间的开始时间和结束时间)
- C#获取本周,本月,本年,本季度等时间
- java 获取本年 本月 本周开始时间(在网上搜的周日被定义为一周的开始,修改后周日为一周的结束)
- javascript获取当天、本周、本月、本年 开始及结束时间
- PHP 获取本年、本周、本月、本日的开始和结束时间
- C# 根据当前时间获取,本周,本月,本季度等时间段 .Net中Exception
- C# 根据当前时间获取,本周,本月,本季度等时间段
- 转:c# 根据当前时间获取,本周,本月,本季度,月初,月末,各个时间段
- C# 根据当前时间获取本月,本周,本季度
- C# 根据当前时间获取,本周,本月,本季度等时间段
- C# 根据当前时间获取,本周,本月,本季度等时间段
- c# DateTime根据当前时间获取,本周,本月,本季度,月初,月末,各个时间段