例如,如果我获得2016年8月,则我应该将开始日期定为2016年7月1日,结束日期定为2016年9月30日(因为这是在今年的第三季度之内)。谁能解释一个逻辑。
public static void printStartEndQuarter(int year, int month) {
double thisMonth = (double)month;
String quarter = thisMonth/3 <= 1 ? "Quarter 1" : thisMonth/3 <= 2 ? "Quarter 2" : thisMonth/3 <= 3 ? "Quarter 3" : "Quarter 4";
if (month % 3 == 2) {
month = month - 1;
}
else if (month % 3 == 0) {
month = month - 2;
}
LocalDate start = LocalDate.of(year, month, 1);
Month endMonth = start.getMonth().plus(2);
LocalDate end = LocalDate.of(year, endMonth, endMonth.length(start.isLeapYear()));
System.out.println("Start Date====" + start);
System.out.println("End Date====" + end);
System.out.println("quarter====" + quarter);
}
希望这对某些人有用,并且适用于任何测试用例。谢谢@fabin。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句