当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net 日期转换为大写汉字

asp.net 日期转换为大写汉字

2018年09月14日  | 移动技术网IT编程  | 我要评论

.net 日期转换为大写汉字

//年份转换为大写汉字
        public static string numtoupper(int num)
         {
             return "零壹贰叁肆伍陆柒捌玖"[num].tostring();
         }

//月份转换大写汉字
        public static string monthtoupper(int month)
        {
            if (month < 10)
            {
                return numtoupper(month);
            }
            else
            {
                if (month == 10) { return "壹拾"; }

                else
                {
                    return "壹拾" + numtoupper(month - 10);
                }
            }
        }


//日期转化为大写汉字
        public static 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()));
                }
            }
        }
static void main(string[] args)
        {
            string year = "2013";
            string retur = string.empty;
            for (int i = 0; i < year.length; i++)
            {
                retur += numtoupper(int.parse(year[i].tostring())).tostring();
            }
            console.writeline(retur + "  年");
            retur = string.empty;
            string month = "12";
            retur = monthtoupper(convert.toint32(month));
            console.writeline(retur + "  月");
            string day = "31";
            retur = daytoupper(convert.toint32(day));
            console.writeline(retur + "  日");
            console.readline();
        }

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网