|
|
@@ -2,7 +2,6 @@ package cn.hutool.core.date;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.comparator.CompareUtil;
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.format.DateParser;
|
|
|
import cn.hutool.core.date.format.DatePrinter;
|
|
|
import cn.hutool.core.date.format.FastDateFormat;
|
|
|
@@ -613,65 +612,19 @@ public class DateUtil extends CalendarUtil {
|
|
|
* @param date 被格式化的日期
|
|
|
* @param isUppercase 是否采用大写形式
|
|
|
* @return 中文日期字符串
|
|
|
- * @since 4.1.19
|
|
|
+ * @since 5.3.9
|
|
|
*/
|
|
|
- public static String formatChineseDate(Date date, boolean isUppercase) {
|
|
|
+ public static String formatChineseDate(Date date, boolean isUppercase, boolean withTime) {
|
|
|
if (null == date) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- String format = DatePattern.CHINESE_DATE_FORMAT.format(date);
|
|
|
- if (isUppercase) {
|
|
|
- final StringBuilder builder = StrUtil.builder(format.length());
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(0, 1)), false));
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(1, 2)), false));
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(2, 3)), false));
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(3, 4)), false));
|
|
|
- builder.append(format, 4, 5);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(5, 7)), false));
|
|
|
- builder.append(format, 7, 8);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(8, 10)), false));
|
|
|
- builder.append(format.substring(10));
|
|
|
- format = builder.toString().replace('零', '〇');
|
|
|
- }
|
|
|
- return format;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 格式化为中文日期格式,如果isUppercase为false,则返回类似:2018年10月24日12时13分14秒,否则返回二〇一八年二月二十四日一十二时一十三分一十四秒
|
|
|
- *
|
|
|
- * @param date 被格式化的日期
|
|
|
- * @param isUppercase 是否采用大写形式
|
|
|
- * @return 中文日期时间串字符串
|
|
|
- * @since 5.3.7
|
|
|
- */
|
|
|
- public static String formatChineseDateTime(Date date, boolean isUppercase) {
|
|
|
- if (null == date) {
|
|
|
- return null;
|
|
|
+ if (false == isUppercase) {
|
|
|
+ return (withTime ? DatePattern.CHINESE_DATE_TIME_FORMAT : DatePattern.CHINESE_DATE_FORMAT).format(date);
|
|
|
}
|
|
|
|
|
|
- String format = DatePattern.CHINESE_DATE_TIME_FORMAT.format(date);
|
|
|
- if (isUppercase) {
|
|
|
- final StringBuilder builder = StrUtil.builder(format.length());
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(0, 1)), false));
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(1, 2)), false));
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(2, 3)), false));
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(3, 4)), false));
|
|
|
- builder.append(format, 4, 5);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(5, 7)), false));
|
|
|
- builder.append(format, 7, 8);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(8, 10)), false));
|
|
|
- builder.append(format, 10, 11);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(11, 13)), false));
|
|
|
- builder.append(format, 13, 14);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(14, 16)), false));
|
|
|
- builder.append(format, 16, 17);
|
|
|
- builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(17, 19)), false));
|
|
|
- builder.append(format.substring(19));
|
|
|
- format = builder.toString().replace('零', '〇');
|
|
|
- }
|
|
|
- return format;
|
|
|
- }
|
|
|
+ return CalendarUtil.formatChineseDate(CalendarUtil.calendar(date), withTime);
|
|
|
+ }
|
|
|
// ------------------------------------ Format end ----------------------------------------------
|
|
|
|
|
|
// ------------------------------------ Parse start ----------------------------------------------
|