zoukankan      html  css  js  c++  java
  • c#时间格式转换汉字大写

    把时间转换为汉字大写

    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()));
                 }
              }
           }
    }
  • 相关阅读:
    vue苦逼自学之路
    第一次博客作业
    u3d学习资料
    leetcode——Divide Two Integers
    leetcode——Swap Nodes in Pairs
    leetcode——Merge k Sorted Lists
    leetcode——Container With Most Water
    leetcode——Regular Expression Matching
    leetcode——Longest Palindromic Substring
    CC_CALLBACK之间的区别
  • 原文地址:https://www.cnblogs.com/moonstars/p/12883094.html
Copyright © 2011-2022 走看看