码迷,mamicode.com
首页 > 其他好文 > 详细

根据身份证算出生日期和性别

时间:2014-12-04 15:31:46      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

public static bool ProcessIdCard(this string idCard, out DateTime birthday, out string genderName)
        {
            bool result;
            birthday = new DateTime();
            genderName = string.Empty;
            try
            {
                string sex;
                string birth;
                if (idCard.Length == 15)
                {
                    birth = idCard.Substring(6, 6).Insert(4, "-").Insert(2, "-");
                    sex = idCard.Substring(12, 3);
                }
                else
                {
                    birth = idCard.Substring(6, 8).Insert(6, "-").Insert(4, "-");
                    sex = idCard.Substring(14, 3);
                }
                genderName = int.Parse(sex) % 2 == 0 ? "" : "";
                result = DateTime.TryParse(birth, out birthday);
            }
            catch (Exception e)
            {
                result = false;
            }
            return result;
        }

 

根据身份证算出生日期和性别

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/vipsoft/p/4142951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!