把时间转换为汉字大写
public class DateTimeConvert
{
public static string ConvertToChineseCapital(DateTime dateTime)
{
var year = YearConvertToChineseCapital(dateTime.Year) + "年";
var month = OtherConvertToChineseCapitaldateTime.Month)+"月";
var day = OtherConvertToChineseCapital(dateTime.Day) + "日";
var hour = OtherConvertToChineseCapital(dateTime.Hour) + "时";
var minute = OtherConvertToChineseCapital(dateTime.Minute) + "分";
return year + month + day + hour + minute;
}
private static string YearConvertToChineseCapital(int year)
{
string str = "";
string yearStr = year.ToString();
int n;
for (int i = 0; i < year.ToString().Length; i++)
{
n = int.Parse(yearStr[i].ToString());
switch (n)
{
case 0: str = str + "零"; break;
case 1: str = str + "壹"; break;
case 2: str = str + "贰"; break;
case 3: str = str + "叁"; break;
case 4: str = str + "肆"; break;
case 5: str = str + "伍"; break;
case 6: str = str + "陆"; break;
case 7: str = str + "柒"; break;
case 8: str = str + "捌"; break;
default: str = str + "玖"; break;
}
}
return str;
}
private static string OtherConvertToChineseCapital(int other)
{
if (other < 10)
{
return "零" + YearConvertToChineseCapital(other);
}
else
{
var str = other.ToString();
if (str[1] == '0')
{
return YearConvertToChineseCapital(int.Parse(str[0].ToString())) + "拾";
}
else
{
return YearConvertToChineseCapital(int.Parse(str[0].ToString())) + "拾"+
YearConvertToChineseCapital(int.Parse(str[1].ToString()));
}
}
}
}