|
|
@@ -30,9 +30,9 @@ public class DateUtil {
|
|
|
|
|
|
public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- public static final String FORMAT_YEAR_WITH_CHINESE_SEPARATOR = "yyyy年";
|
|
|
- public static final String FORMAT_MONTH_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED = "yyyy年M月";
|
|
|
- public static final String FORMAT_DATE_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED = "yyyy年M月d日";
|
|
|
+ public static final String YEAR_FORMAT_NUM = "yyyy";
|
|
|
+ public static final String YEAR_FORMAT_WITH_CHINESE_SEPARATOR = "yyyy年";
|
|
|
+ public static final String DATE_FORMAT_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED = "yyyy年M月d日";
|
|
|
|
|
|
/**
|
|
|
* LocalDateTime 转时间戳
|
|
|
@@ -163,13 +163,24 @@ public class DateUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 将日期格式化成纯数字表示的年份
|
|
|
+ *
|
|
|
+ * @param date
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String formatYearToNum(Date date) {
|
|
|
+ SimpleDateFormat destDateFormat = new SimpleDateFormat(YEAR_FORMAT_NUM);
|
|
|
+ return destDateFormat.format(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 将日期格式化成用中文分割符表示的年份
|
|
|
*
|
|
|
* @param date
|
|
|
* @return
|
|
|
*/
|
|
|
public static String formatYearWithChineseSeparator(Date date) {
|
|
|
- SimpleDateFormat destDateFormat = new SimpleDateFormat(FORMAT_YEAR_WITH_CHINESE_SEPARATOR);
|
|
|
+ SimpleDateFormat destDateFormat = new SimpleDateFormat(YEAR_FORMAT_WITH_CHINESE_SEPARATOR);
|
|
|
return destDateFormat.format(date);
|
|
|
}
|
|
|
|
|
|
@@ -183,7 +194,7 @@ public class DateUtil {
|
|
|
*/
|
|
|
public static String formatDateWithChineseSeparatorAndNoZeroFilled(String date, String srcFormat) throws Exception {
|
|
|
SimpleDateFormat srcDateFormat = new SimpleDateFormat(srcFormat);
|
|
|
- SimpleDateFormat destDateFormat = new SimpleDateFormat(FORMAT_DATE_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED);
|
|
|
+ SimpleDateFormat destDateFormat = new SimpleDateFormat(DATE_FORMAT_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED);
|
|
|
return destDateFormat.format(srcDateFormat.parse(date));
|
|
|
}
|
|
|
|
|
|
@@ -194,7 +205,7 @@ public class DateUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static String formatDateWithChineseSeparatorAndNoZeroFilled(Date date) {
|
|
|
- SimpleDateFormat destDateFormat = new SimpleDateFormat(FORMAT_DATE_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED);
|
|
|
+ SimpleDateFormat destDateFormat = new SimpleDateFormat(DATE_FORMAT_WITH_CHINESE_SEPARATOR_AND_NO_ZERO_FILLED);
|
|
|
return destDateFormat.format(date);
|
|
|
}
|
|
|
|