C# 日期转换为中文大写

/// <summary>
/// 日期转换为中文大写
/// </summary>
public class UpperConvert
{
    public UpperConvert()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    //把数字转换为大写
        public string numtoUpper(int num)
        {
            String str=num.ToString();
            string rstr = "";
            int n;
            for (int i = 0; i < str.Length; i++) 
            {
                n =Convert.ToInt16(str[i].ToString());//char转数字,转换为字符串,再转数字
                switch (n) 
                {
                    case 0:rstr=rstr+"";break;
                    case 1:rstr=rstr+"";break;
                    case 2:rstr=rstr+"";break;
                    case 3:rstr=rstr+"";break;
                    case 4:rstr=rstr+"";break;
                    case 5:rstr=rstr+"";break;
                    case 6:rstr=rstr+"";break;
                    case 7:rstr=rstr+"";break;
                    case 8:rstr=rstr+"";break;
                    default:rstr=rstr+"";break; 
                }

            }
            return rstr;
        }
        //月转化为大写
        public string monthtoUpper(int month)
        {
            if (month < 10)
            {
                return numtoUpper(month);
            }
            else
                if (month == 10) { return ""; }

                else
                {
                    return "" + numtoUpper(month - 10);
                }
        }
        //日转化为大写
        public string daytoUpper(int day)
        {
            if (day < 20)
            {
                return monthtoUpper(day);
            }
            else
            {
                String str = day.ToString();
                if (str[1] == '0')
                {
                    return numtoUpper(Convert.ToInt16(str[0].ToString()))+"" ; 
                }
                else
                {
                    return numtoUpper(Convert.ToInt16(str[0].ToString())) + "" 
                        + numtoUpper(Convert.ToInt16(str[1].ToString())); 
                }
            }
        }
        //日期转换为大写
        public string  dateToUpper(System.DateTime date)
        {
            int year = date.Year;
            int month = date.Month;
            int day = date.Day;
            return numtoUpper(year) + "" + monthtoUpper(month) + "" + daytoUpper(day) + "";

        }
}

 

posted @ 2015-12-16 10:08  韩梦芫  阅读(4231)  评论(0编辑  收藏  举报