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;
                }
            }
        }

  • 相关阅读:
    存储过程
    Apache服务器
    SpringMVC (<context:include-filter>和<context:exclude-filter>的使用)
    虚拟机centos 同一个tomcat、不同端口访问不同的项目
    CentOS系统下搭建tomcat服务器
    nginx配置负载均衡
    配置plsql远程连接oracle数据库
    Nginx安装
    Centos6.5系统关闭防火墙
    禁止Centos7系统yum自动下载更新
  • 原文地址:https://www.cnblogs.com/88223100/p/1181225.html
Copyright © 2011-2022 走看看