public static String ToChineseYearAndMonth(this DateTime dt) { string[] chineseNumbers = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; // 将年份和月份转换为中文文字 string chineseYear = YearToChinese(dt.Year); string chineseMonth = MonthToChinese(dt.Month); // 构造中文格式的日期字符串 string formattedDate = $"{chineseYear}年{chineseMonth}月"; return formattedDate; string MonthToChinese(int number) { if (number == 10) { return "十"; } else if (number > 10) { return "十" + chineseNumbers[number % 10]; } else { return chineseNumbers[number]; } } string YearToChinese(int number) { StringBuilder sb = new StringBuilder(4); while (number > 0) { int digit = number % 10; sb.Insert(0, chineseNumbers[digit]); number /= 10; } return sb.ToString(); } }
DateTime字段换成类似二〇二三年十一月十七日这种中文文字格式.部分报告可能需要.
标签:10,return,string,C#,number,DateTime,字段,chineseNumbers From: https://www.cnblogs.com/MarsPanda/p/17838259.html