日期转换为中文日期
public static string GetChineseDate(DateTime dateTime,bool usingOldFont=true)
{
string resultString = "";
resultString += GetChineseDate2(dateTime.Year, 1, usingOldFont) + "年" + GetChineseDate2(dateTime.Month, 2, usingOldFont) + "月" + GetChineseDate2(dateTime.Day, 3, usingOldFont) + "日";
return resultString;
}
private static string GetChineseDate2(int val, int type, bool usingOldFont)
{
string resultString = "";
string[] arrConvertValue1 = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
string[] arrConvertValue2 = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
string tenStr = usingOldFont ? "拾" : "十";
char[] arrValue = val.ToString().ToCharArray();
switch (type)
{
case 1:
for (int i = 0; i < arrValue.Length; i++)
{
resultString +=
usingOldFont ? arrConvertValue1[Convert.ToInt16(arrValue[i].ToString())] : arrConvertValue2[Convert.ToInt16(arrValue[i].ToString())];
}
break;
case 2:
if (val < 10)
{
resultString +=
usingOldFont ? arrConvertValue1[Convert.ToInt16(arrValue[0].ToString())] : arrConvertValue2[Convert.ToInt16(arrValue[0].ToString())];
}
else
{
resultString += tenStr;
resultString +=
usingOldFont ? arrConvertValue1[Convert.ToInt16(arrValue[1].ToString())] : arrConvertValue2[Convert.ToInt16(arrValue[1].ToString())];
}
break;
case 3:
if (val < 20)
{
for (int i = 0; i < arrValue.Length; i++)
{
resultString +=
usingOldFont ? arrConvertValue1[Convert.ToInt16(arrValue[i].ToString())] : arrConvertValue2[Convert.ToInt16(arrValue[i].ToString())];
}
}
else
{
if (arrValue[1].ToString() == "0")
{
resultString +=
usingOldFont ? arrConvertValue1[Convert.ToInt16(arrValue[0].ToString())] : arrConvertValue2[Convert.ToInt16(arrValue[0].ToString())] + tenStr;
}
else
{
resultString +=
usingOldFont ? arrConvertValue1[Convert.ToInt16(arrValue[0].ToString())] + tenStr + arrConvertValue1[Convert.ToInt16(arrValue[1].ToString())]
:
arrConvertValue2[Convert.ToInt16(arrValue[0].ToString())] + tenStr + arrConvertValue2[Convert.ToInt16(arrValue[1].ToString())];
}
}
break;
}
return resultString;
}