Browse Source

漏题

dev_shibei_match
yinzuomei 5 years ago
parent
commit
13a5e79340
  1. 36
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java

36
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java

@ -9,6 +9,7 @@
package com.epmet.commons.tools.utils;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
@ -33,6 +34,11 @@ public class DateUtils {
public static final List<Integer> Q3Months = Arrays.asList(7, 8, 9);
public static final List<Integer> Q4Months = Arrays.asList(10, 11, 12);
public static final List<String> Q1MonthsStrList = Arrays.asList("1", "2", "3","01","02","03");
public static final List<String> Q2MonthsStrList = Arrays.asList("4", "5", "6","04", "05", "06");
public static final List<String> Q3MonthsStrList = Arrays.asList("7", "8", "9","07", "08", "09");
public static final List<String> Q4MonthsStrList = Arrays.asList("10", "11", "12");
/** 时间格式(yyyy-MM-dd) */
public final static String DATE_PATTERN = "yyyy-MM-dd";
/** 时间格式(yyyy-MM-dd HH:mm:ss) */
@ -298,6 +304,29 @@ public class DateUtils {
return 4;
}
/**
* 获取季度
* @param monthId yyyyMM
* @return yyyyQ1yyyyQ2yyyyQ3yyyyQ4
*/
public static String getQuarterId(String monthId) {
String year = monthId.substring(0, 4);
String month = monthId.substring(4, 6);
if (Q1MonthsStrList.contains(month)) {
return year.concat("Q1");
}
if (Q2MonthsStrList.contains(month)) {
return year.concat("Q2");
}
if (Q3MonthsStrList.contains(month)) {
return year.concat("Q3");
}
if(Q4MonthsStrList.contains(month)){
return year.concat("Q4");
}
return StrConstant.EPMETY_STR;
}
/**
* 根据季度查询季度的月份列表
* @param quarterIndex
@ -557,4 +586,11 @@ public class DateUtils {
System.out.println(comparteDate(yesterDay,today));
System.out.println(comparteDate(tomorrow,today));
}
public static String getYearId(String monthId) {
if (StringUtils.isNotBlank(monthId) && monthId.length() > 4) {
return monthId.substring(NumConstant.ZERO, NumConstant.FOUR);
}
return StrConstant.EPMETY_STR;
}
}

Loading…
Cancel
Save