- static void Main(string[] args)
- {
- string[] strDate = getDate("2012年12月13日");
- string year = day(strDate[0]);
- string month = days(strDate[1]);
- string strday = days(strDate[2]);
- Console.WriteLine("{0}年{1}月{2}日", year, month, strday);
- Console.ReadKey();
- }
- static string[] getDate(string date)
- {
- string[] strdate = date.Split(new char[] { '年', '月', '日' });
- return strdate;
- }
- /// <summary>
- /// 适用于年份
- /// </summary>
- /// <param name="d">日期的阿拉伯数字</param>
- /// <returns>大写数字</returns>
- static string day(string d)
- {
- char[] cday = new char[] { '零', '一', '二', '三', '四', '五', '六', '七', '八', '九' };
- char[] cd = d.ToCharArray();
- string rd = "";
- foreach (char i in cd)
- {
- rd += cday[i - 48];
- }
- return rd;
- }
- /// <summary>
- /// 适用于月和日
- /// </summary>
- /// <param name="d">日期的阿拉伯数字</param>
- /// <returns>大写数字</returns>
- static string days(string d)
- {
- char[] cday = new char[] { '十', '一', '二', '三', '四', '五', '六', '七', '八', '九' };
- char[] cd = d.ToCharArray();
- string rd = "";
- if (cd.Length > 1 && !cd[1].Equals('0'))
- {
- if (cd[0].Equals('1'))
- {
- rd = cday[0] + "" + cday[cd[1] - 48];
- }
- else {
- rd = cday[cd[0] - 48] + "十" + cday[cd[1] - 48];
- }
- }
- else if (cd.Length > 1 && cd[1].Equals('0'))
- {
- if (cd[0].Equals('1'))
- {
- rd = cday[0].ToString();
- }
- else
- {
- rd = cday[cd[0] - 48] + "十";
- }
- }
- else {
- rd = day(d);
- }
- return rd;
- }
复制代码 |