mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复:格式化为中文日期时,0被处理为空串
This commit is contained in:
parent
4b02bc7287
commit
8c20364c2c
@ -555,6 +555,12 @@ public class CalendarUtil {
|
||||
result.append(NumberChineseFormatter.formatThousand(day, false));
|
||||
result.append('日');
|
||||
|
||||
// 时分秒中零不需要替换
|
||||
String temp = result.toString().replace('零', '〇');
|
||||
result.delete(0, result.length());
|
||||
result.append(temp);
|
||||
|
||||
|
||||
if (withTime) {
|
||||
// 时
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
@ -570,7 +576,7 @@ public class CalendarUtil {
|
||||
result.append('秒');
|
||||
}
|
||||
|
||||
return result.toString().replace('零', '〇');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,6 +289,9 @@ public class DateUtilTest {
|
||||
public void formatChineseDateTimeTest() {
|
||||
String formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2018-02-24 12:13:14"), true, true);
|
||||
Assert.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", formatChineseDateTime);
|
||||
|
||||
formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2022-01-18 12:00:00"), true, true);
|
||||
Assert.assertEquals("二〇二二年一月十八日十二时零分零秒", formatChineseDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user