根据当前日期获取当前季度范围
2013-01-28 15:41
330 查看
private static SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd"); /** * 当前季度的开始时间,即2012-01-1 00:00:00 * @return */ public static Date getCurrentQuarterStartTime() { Calendar c = Calendar.getInstance(); int currentMonth = c.get(Calendar.MONTH) + 1; Date now = null; try { if (currentMonth >= 1 && currentMonth <= 3) c.set(Calendar.MONTH, 0); else if (currentMonth >= 4 && currentMonth <= 6) c.set(Calendar.MONTH, 3); else if (currentMonth >= 7 && currentMonth <= 9) c.set(Calendar.MONTH, 4); else if (currentMonth >= 10 && currentMonth <= 12) c.set(Calendar.MONTH, 9); c.set(Calendar.DATE, 1); System.out.println(c.getTime()); now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00"); } catch (Exception e) { e.printStackTrace(); } return now; } /** * 当前季度的结束时间,即2012-03-31 23:59:59 * @return */ public static Date getCurrentQuarterEndTime() { Calendar c = Calendar.getInstance(); int currentMonth = c.get(Calendar.MONTH) + 1; Date now = null; try { if (currentMonth >= 1 && currentMonth <= 3) { c.set(Calendar.MONTH, 2); c.set(Calendar.DATE, 31); } else if (currentMonth >= 4 && currentMonth <= 6) { c.set(Calendar.MONTH, 5); c.set(Calendar.DATE, 30); } else if (currentMonth >= 7 && currentMonth <= 9) { c.set(Calendar.MONTH, 8); c.set(Calendar.DATE, 30); } else if (currentMonth >= 10 && currentMonth <= 12) { c.set(Calendar.MONTH, 11); c.set(Calendar.DATE, 31); } now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59"); } catch (Exception e) { e.printStackTrace(); } return now; }原文转自:http://www.myexception.cn/program/654131.html
相关文章推荐
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- 根据年份获取周次,根据周次获取日期范围,获取当前年份,周次列表信息。
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- js根据当前时间获取指定范围内的时间段日期
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度及常见日期方法荟萃 )
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- 根据当前时间确定日期范围(本周、本月、本季度、本年度)
- C# 根据当前时间获取本周、本月、本季度、本年的始末日期
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)
- linux 根据当前日期获取上个季度的第一天和最后一天
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)(转)
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度及常见日期方法荟萃
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- C#根据当前时间确定日期范围(本周、本月、本季度、本年度)[转]