zoukankan      html  css  js  c++  java
  • C#数字日期装换为中文日期

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 namespace ConsoleApplication1
     6 {
     7     class Program
     8     {
     9         
    10         static void Main(string[] args)
    11         {
    12             Console.WriteLine("请输入一个日期:");
    13             string strDate = Console.ReadLine();
    14             string dc = Baodate2Chinese(strDate);
    15             Console.WriteLine(dc);
    16         }
    17 
    18         private static string Baodate2Chinese(string strDate)
    19         {
    20             char[] strChinese= new char[] {
    21                  '','','','','','','','','','',''
    22              };
    23             StringBuilder result = new StringBuilder();
    24 
    25             //// 依据正则表达式判断参数是否正确
    26             //Regex theReg = new Regex(@"(d{2}|d{4})(/|-)(d{1,2})(/|-)(d{1,2})");
    27 
    28             if (!string.IsNullOrEmpty(strDate))
    29             {
    30                 // 将数字日期的年月日存到字符数组str中
    31                 string[] str = null;
    32                 if (strDate.Contains("-"))
    33                 {
    34                     str = strDate.Split('-');
    35                 }
    36                 else if (strDate.Contains("/"))
    37                 {
    38                     str = strDate.Split('/');
    39                 }
    40                 // str[0]中为年,将其各个字符转换为相应的汉字
    41                 for (int i = 0; i < str[0].Length; i++)
    42                 {
    43                     result.Append(strChinese[int.Parse(str[0][i].ToString())]);
    44                 }
    45                 result.Append("");
    46 
    47                 // 转换月
    48                 int month = int.Parse(str[1]);
    49                 int MN1 = month / 10;
    50                 int MN2 = month % 10;
    51 
    52                 if (MN1 > 1)
    53                 {
    54                     result.Append(strChinese[MN1]);
    55                 }
    56                 if (MN1 > 0)
    57                 {
    58                     result.Append(strChinese[10]);
    59                 }
    60                 if (MN2 != 0)
    61                 {
    62                     result.Append(strChinese[MN2]);
    63                 }
    64                 result.Append("");
    65 
    66                 // 转换日
    67                 int day = int.Parse(str[2]);
    68                 int DN1 = day / 10;
    69                 int DN2 = day % 10;
    70 
    71                 if (DN1 > 1)
    72                 {
    73                     result.Append(strChinese[DN1]);
    74                 }
    75                 if (DN1 > 0)
    76                 {
    77                     result.Append(strChinese[10]);
    78                 }
    79                 if (DN2 != 0)
    80                 {
    81                     result.Append(strChinese[DN2]);
    82                 }
    83                 result.Append("");
    84             }
    85             else
    86             {
    87                 throw new ArgumentException();
    88             }
    89 
    90             return result.ToString();
    91         }
    92     }
    93 }
    View Code
    人的潜能是能够挖掘的,当你说太晚了的时候,你一定要谨慎,它可能是你退却的借口,没有谁能够阻止你成功,除了你自己,该炫自己的时候,千万别对自己手软!
  • 相关阅读:
    css3 @page
    Python:GUI
    Python: simple drawings
    JQuery 实现多个checkbox 只选中一个
    pgwSlideshow.js
    Html5: Drawing with text
    HTML5 Video player jQuery plugin
    cSharp:反射 Reflection
    机器学习基础---无监督学习之异常检测
    机器学习作业---主成分分析PCA
  • 原文地址:https://www.cnblogs.com/FengleQin/p/5976175.html
Copyright © 2011-2022 走看看