• 通过身份证号码取得生日的一段代码(支持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;
                }
            }
        }

  • 相关阅读:
    虚拟主机的陷阱
    http://www.xmenglish.com/(外贸知识网站)
    Highlight Table Row
    让你从电脑维修新手到高手
    Flash 视频教程
    ASP Comparison Operators Logical Operators
    Linux 虚拟机 NAT方式上网设置
    vim技巧
    25 条 SSH 命令和技巧
    linux下添加路由的方法
  • 原文地址:https://www.cnblogs.com/88223100/p/1181225.html
Copyright © 2020-2023  润新知