您的位置:首页 > 其它

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

2014-12-04 15:17 375 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: