欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于ASP.NET實(shí)現(xiàn)日期轉(zhuǎn)為大寫的漢字

 更新時(shí)間:2016年08月17日 11:14:02   投稿:daisy  
在寫代碼時(shí)遇到一個(gè)需要將日期轉(zhuǎn)換為中文大寫日期的問題,網(wǎng)上找了找,示例不是很多,只有javascript代碼的,下面整理下在ASP.NET中怎么實(shí)現(xiàn)。

這篇文章主要介紹的是利用ASP.NET將日期格式轉(zhuǎn)為大寫漢字,比如: “2013年12月3日” 轉(zhuǎn)換成 “貳零壹叁年拾貳月叁日”,下面一起來看看怎么實(shí)現(xiàn)。

一樣話不多說,直接上代碼

//年份轉(zhuǎn)換為大寫漢字
  public static string numtoUpper(int num)
   {
    return "零壹貳叁肆伍陸柒捌玖"[num].ToString();
   }

//月份轉(zhuǎn)換大寫漢字
  public static string monthtoUpper(int month)
  {
   if (month < 10)
   {
    return numtoUpper(month);
   }
   else
   {
    if (month == 10) { return "壹拾"; }

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


//日期轉(zhuǎn)化為大寫漢字
  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 = "3";
   retur = daytoUpper(Convert.ToInt32(day));
   Console.WriteLine(retur + " 日");
   Console.ReadLine();
  }

以上就是利用ASP.NET將日期格式轉(zhuǎn)為大寫漢字的全部內(nèi)容,希望本文的內(nèi)容對大家使用ASP.NET的時(shí)候能有所幫助。

相關(guān)文章

最新評論