一、方法:
export function dateToChnese(strDate) {let dateMap = {year: "",month: "",day: ""}if (!strDate || strDate.length == 0) return dateMap;const chineseDigit = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];strDate = strDate.replace(/\-/g, "");if (strDate.length < 4) return dateMap;const year = strDate.substring(0, 4);let strYear = "";for (let i = 0; i < 4; i++) {strYear = strYear + chineseDigit[parseInt(year[i])];}dateMap["year"] = strYear;if (strDate.length < 6) return dateMap;const month = strDate.substring(4, 6);let strMonth = "";if (month.substring(1) > 0) {strMonth = chineseDigit[month.substring(1)] + strMonth;}if (month.substring(0, 1) > 0) {strMonth = "拾" + strMonth;} else {strMonth = chineseDigit[month.substring(0, 1)] + strMonth;}dateMap["month"] = strMonth;if (strDate.length < 8) return dateMap;const day = strDate.substring(6, 8);let strDay = "";if (day.substring(1) > 0) {strDay = chineseDigit[day.substring(1)] + strDay;}if (day.substring(0, 1) > 0) {strDay = chineseDigit[day.substring(0, 1)] + "拾" + strDay;} else {strDay = chineseDigit[day.substring(0, 1)] + strDay;}dateMap["day"] = strDay;return dateMap;
}
二、使用效果:
