您的位置:首页 > 编程语言 > Java开发

【java】字符串日期转换成中文格式日期

2011-10-14 10:00 531 查看
/**
* 字符串日期转换成中文格式日期
* @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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐