/**
* 字符串日期转换成中文格式日期
* @param date 字符串日期 yyyy-MM-dd
* @return yyyy年MM月dd日
* @throws Exception
*/
public static String dateToCnDate(String date) {
String result = "";
String[] cnDate = new String[]{"○","一","二","三","四","五","六","七","八","九"};
String ten = "十";
String[] dateStr = date.split("-");
for (int i=0; i<dateStr.length; i++) {
for (int j=0; j<dateStr[i].length(); j++) {
String charStr = dateStr[i];
String str = String.valueOf(charStr.charAt(j));
if (charStr.length() == 2) {
if (charStr.equals("10")) {
result += ten;
break;
} else {
if (j == 0) {
if (charStr.charAt(j) == '1')
result += ten;
else if (charStr.charAt(j) == '0')
result += "";
else
result += cnDate[Integer.parseInt(str)] + ten;
}
if (j == 1) {
if (charStr.charAt(j) == '0')
result += "";
else
result += cnDate[Integer.parseInt(str)];
}
}
} else {
result += cnDate[Integer.parseInt(str)];
}
}
if (i == 0) {
result += "年";
continue;
}
if (i == 1) {
result += "月";
continue;
}
if (i == 2) {
result += "日";
continue;
}
}
return result;
} 【java】字符串日期转换成中文格式日期
最新推荐文章于 2023-06-10 11:53:51 发布
本文提供了一个将字符串日期格式转换为中文日期格式的方法,详细解释了如何解析输入的日期字符串,并将其转换为对应的中文年、月、日格式。
1453

被折叠的 条评论
为什么被折叠?



