zoukankan      html  css  js  c++  java
  • 步步为营-13-日期转化

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 日期的转换
    {
        //2012-12-21
        //2009-7-9
        //2010-10-24
        //2010-10-20
        class Program
        {
            //定义数据字典
            public static Dictionary<string, string> dict = new Dictionary<string, string>();
            static void Main(string[] args)
            {
               //0数据字典初始化
                DictInitialization();
                while (true)
                {
                    Console.WriteLine("请输入要转换的日期");
                    string strChineseDate = Console.ReadLine();
                    //1 分割年月日
                    string[] strDates = strChineseDate.Split(new char[3] { '', '', '' });
                    //2 获得年的转换
                    string year = GetYear(strDates[0]);
                    //3 获得月的转换
                    string moon = GetMoon(strDates[1]);
                    //4 获得日的转换
                    string day = GetDay(strDates[2]);
                    Console.WriteLine(year + "-" + moon + "-" + day);
                }
            }
           
         
            /// <summary>
            ///0数据字典初始化       
            /// </summary>
            public static void DictInitialization() 
            {
                dict.Add("", "0");
                dict.Add("", "1");
                dict.Add("", "2");
                dict.Add("", "3");
                dict.Add("", "4");
                dict.Add("", "5");
                dict.Add("", "6");
                dict.Add("", "7");
                dict.Add("", "8");
                dict.Add("", "9");
                dict.Add("", "10");
                dict.Add("十一", "11");
                dict.Add("十二", "12");
                dict.Add("十三", "13");
                dict.Add("十四", "14");
                dict.Add("十五", "15");
                dict.Add("十六", "16");
                dict.Add("十七", "17");
                dict.Add("十八", "18");
                dict.Add("十九", "19");
                dict.Add("二十", "20");
                dict.Add("二十一", "21");
                dict.Add("二十二", "22");
                dict.Add("二十三", "23");
                dict.Add("二十四", "24");
                dict.Add("二十五", "25");
                dict.Add("二十六", "26");
                dict.Add("二十七", "27");
                dict.Add("二十八", "28");
                dict.Add("二十九", "29");
                dict.Add("三十", "30");
                dict.Add("三十一", "31");
                     
            }
            //2获取年
            public static string GetYear(string year) 
            {
                string result = string.Empty;
             
                foreach (var item in year)
                {
                    result += dict[item.ToString()];
                }
                return result;
            }
            //3获取月
            public static string GetMoon(string moon)
            {
                string result = string.Empty;
                result = dict[moon.ToString()];
                return result;
            }
            public static string GetDay(string moon)
            {
                string result = string.Empty;
                result = dict[moon.ToString()];
                return result;
            }
        }
    }
    View Code

  • 相关阅读:
    haproxy 基于 cookie 的会话保持
    haproxy 透明代理
    haproxy tcp keepalive
    haproxy 支持 websocket
    python 中给文件加锁
    使用python生成二维码
    python中的uuid简介
    django建表报错
    pip安装第三方包PIL失败
    python获取mac地址的方法
  • 原文地址:https://www.cnblogs.com/YK2012/p/6718138.html
Copyright © 2011-2022 走看看