mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
commit
ee80e8c195
@ -164,6 +164,11 @@ public class NumberChineseFormatter {
|
|||||||
*/
|
*/
|
||||||
public static String formatThousand(int amount, boolean isUseTraditional){
|
public static String formatThousand(int amount, boolean isUseTraditional){
|
||||||
Assert.checkBetween(amount, -999, 999, "Number support only: (-999 ~ 999)!");
|
Assert.checkBetween(amount, -999, 999, "Number support only: (-999 ~ 999)!");
|
||||||
|
|
||||||
|
// thousandToChinese方法对0不处理,此处直接返回"零"
|
||||||
|
if (amount == 0) {
|
||||||
|
return String.valueOf(DIGITS[0]);
|
||||||
|
}
|
||||||
final String chinese = thousandToChinese(amount, isUseTraditional);
|
final String chinese = thousandToChinese(amount, isUseTraditional);
|
||||||
if(amount < 20 && amount > 10){
|
if(amount < 20 && amount > 10){
|
||||||
// "十一"而非"一十一"
|
// "十一"而非"一十一"
|
||||||
|
@ -555,6 +555,12 @@ public class CalendarUtil {
|
|||||||
result.append(NumberChineseFormatter.formatThousand(day, false));
|
result.append(NumberChineseFormatter.formatThousand(day, false));
|
||||||
result.append('日');
|
result.append('日');
|
||||||
|
|
||||||
|
// 时分秒中零不需要替换
|
||||||
|
String temp = result.toString().replace('零', '〇');
|
||||||
|
result.delete(0, result.length());
|
||||||
|
result.append(temp);
|
||||||
|
|
||||||
|
|
||||||
if (withTime) {
|
if (withTime) {
|
||||||
// 时
|
// 时
|
||||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
@ -570,7 +576,7 @@ public class CalendarUtil {
|
|||||||
result.append('秒');
|
result.append('秒');
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.toString().replace('零', '〇');
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -289,6 +289,9 @@ public class DateUtilTest {
|
|||||||
public void formatChineseDateTimeTest() {
|
public void formatChineseDateTimeTest() {
|
||||||
String formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2018-02-24 12:13:14"), true, true);
|
String formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2018-02-24 12:13:14"), true, true);
|
||||||
Assert.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", formatChineseDateTime);
|
Assert.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", formatChineseDateTime);
|
||||||
|
|
||||||
|
formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2022-01-18 12:00:00"), true, true);
|
||||||
|
Assert.assertEquals("二〇二二年一月十八日十二时零分零秒", formatChineseDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user