返回基于ASP.N......登陆

基于ASP.NET实现日期转为大写的汉字

巴扎黑2017-01-12 11:44:21437

这篇文章主要介绍的是利用ASP.NET将日期格式转为大写汉字,比如: “2013年12月3日” 转换成 “贰零壹叁年拾贰月叁日”,下面一起来看看怎么实现。

一样话不多说,直接上代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

//年份转换为大写汉字

  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()));

    }

   }

  }

更多关于基于ASP.NET实现日期转为大写的汉字请关注PHP中文网(www.php.cn)其他文章!

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送