将普通日期格式:“2011年6月4日” 转换成汉字日期格式:“二零一一年六月四日”。暂时不考虑10日、13日、23日等“带十”的问题。

namespace _03
{
class Program
{
//将普通日期格式:“2011年6月4日” 转换成汉字日期格式:“二零一一年六月四日”。暂时不考虑10日、13日、23日等“带十”的问题。

static void Main(string[] args)
{
string str="2011年6月4日";
int year = str.IndexOf("年");
int month = str.IndexOf("月");
int day=str.IndexOf("日");
string[] strdateymd={"年","月","日"};
string strs = "";
string[] strdate = str.Split(new string[]{"年","月","日"},StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i<strdate.Length;i++ )
{
for (int j = 0; j < strdate[i].Length;j++ )
{
strs+= GetDate(strdate[i][j].ToString());
}
strs +=strdateymd[i];
}
Console.WriteLine(strs);
}

private static string GetDate(string num)
{
string str = "";
switch (num)
{
case "0": str = "零"; break;
case "1": str = "一"; break;
case "2": str = "二"; break;
case "3": str = "三"; break;
case "4": str = "四"; break;
case "5": str = "五"; break;
case "6": str = "六"; break;
case "7": str = "七"; break;
case "8": str = "八"; break;
case "9": str = "九"; break;
default:
break;
}
return str;

}
}
}

posted @ 2016-12-07 10:59  温柔牛  阅读(212)  评论(0编辑  收藏  举报