[英]How to get today's date as quarterly divided
將給出今天的日期和
一月、四月、七月、十月 = 1
二月、五月、八月、十一月 = 2
三月、六月、九月、十二月 = 3
應該打印。 示例:12 月是季度的第 3 個月,所以答案是 3。有沒有更好的解決方案?
public int getValue() {
switch (LocalDate.now().getMonthValue()) {
case 1:
case 4:
case 7:
case 10:
return 1;
case 2:
case 5:
case 8:
case 11:
return 2;
case 3:
case 6:
case 9:
case 12:
return 3;
default:
throw new IllegalStateException("Unexpected value");
}
public int getValue(int month) {
return month % 3 == 0 ? 3 : month % 3;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.