java 获取季度至今环比日期
/**
* 不完整季度-季度至今环比
*
* @param logicDt
* @return Timestamp
*/
public static Long cycSeasonAccu(String logicDt) throws ParseException {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
Date date = sdf.parse(logicDt);
calendar.setTime(date);
int currentMonth = calendar.get(Calendar.MONTH) + 1; //calendar 月份是从0开始
int year = calendar.get(Calendar.YEAR);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int cycSeasonMonth = calendar.get(Calendar.MONTH) - 3;
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, cycSeasonMonth);
System.out.println(“year” + calendar.get(Calendar.YEAR) + "–month : " + calendar.get(Calendar.MONTH) + " dayOfMonth: " + dayOfMonth);
//闰年2月日期特殊逻辑
if (calendar.get(Calendar.MONTH) + 1 != 2 || (calendar.get(Calendar.MONTH) + 1 == 2 && dayOfMonth <= 28)) {
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
} else {
String lastDayOfMonth = getLastDayOfMonth(calendar.get(Calendar.YEAR), 2);
calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth(lastDayOfMonth));
}
return getTimestamp(calendar.getTime());
}
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了环比日期的获取使用。