日期转换为中文日期

        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;
}

 

posted @ 2012-02-03 18:10  南阳·源  阅读(478)  评论(0编辑  收藏  举报