分类:
ASP.NET
获取身份证中的性别,代码如下:
public static bool GetGenderByIdCard(string idCard)
{
if (string.IsNullOrWhiteSpace(idCard))
{
return false;
}
return Convert.ToBoolean(int.Parse(idCard.Substring(16, 1)) % 2);
}获取身份证中的年龄,代码如下:
public static int GetAgeByIdCard(string idCard)
{
int age = 0;
if (!string.IsNullOrWhiteSpace(idCard))
{
var subStr = string.Empty;
if (idCard.Length == 18)
{
subStr = idCard.Substring(6, 8).Insert(4, "-").Insert(7, "-");
}
else if (idCard.Length == 15)
{
subStr = ("19" + idCard.Substring(6, 6)).Insert(4, "-").Insert(7, "-");
}
TimeSpan ts = DateTime.Now.Subtract(Convert.ToDateTime(subStr));
age = ts.Days / 365;
}
return age;
}
————————————————
版权声明:本文为CSDN博主「vil du」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/My_ben/article/details/83985462评价
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256
50010702506256
欢迎加群交流技术