zoukankan      html  css  js  c++  java
  • 通过身份证号码取得生日的一段代码(支持18位和15位身份证)

        /// <summary>
        /// 根据身份证号码取得生日
        /// </summary>
        /// <param name="cardID">身份证号码</param>
        /// <returns>生日</returns>
        public string GetBirthday(string cardID)
        {
            string birthday;
            if (cardID.Length == 18)
            {
                string str_year = cardID.Substring(6, 4);
                string str_month = cardID.Substring(10, 2);
                string str_day = cardID.Substring(12, 2);

                int year = Convert.ToInt16(str_year);
                int month = Convert.ToInt16(str_month);
                int day = Convert.ToInt16(str_day);
                if ((year > 1800 && year < 2500) && (month <= 12) && (day <= 31))
                {
                    birthday = year.ToString() + "年" + month.ToString() + "月" + day.ToString() + "日";
                    return birthday;
                }
                else
                {
                    RegisterStartupScript("提示", "<script> alert('获取生日时出错!')</script>");
                    return null;
                }
            }
            else
            {
                string str_year = cardID.Substring(6, 2);
                string str_month = cardID.Substring(8, 2);
                string str_day = cardID.Substring(10, 2);

                int year = Convert.ToInt16(str_year);
                int month = Convert.ToInt16(str_month);
                int day = Convert.ToInt16(str_day);
                if ((month <= 12) && (day <= 31))
                {
                    birthday = "19" + year.ToString() + "年" + month.ToString() + "月" + day.ToString() + "日";
                    return birthday;
                }
                else
                {
                    RegisterStartupScript("提示", "<script> alert('获取生日时出错!')</script>");
                    return null;
                }
            }
        }

  • 相关阅读:
    Windows设置多用户同时远程登录
    Scala配置环境变量windows
    Java学习|强引用,软引用,弱引用,幻想引用有什么区别?
    Java学习|Exception和Error有什么区别?
    关于异常处理的几点建议
    win Server 2008 笔记
    .Net 初步学习笔记之三---变量
    认识与入门 MarkDown 标记语言
    C# winform基础 1、Timer不起作用 2、 设置图片透明
    IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2
  • 原文地址:https://www.cnblogs.com/88223100/p/1181225.html
Copyright © 2011-2022 走看看