首页 > 代码库 > 根据身份证算出生日期和性别

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

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

 

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