增加数据穿透界面
This commit is contained in:
@@ -103,5 +103,50 @@ namespace BLL
|
||||
return true;//符合15位身份证标准
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 根据身份证号码获取生日
|
||||
/// </summary>
|
||||
/// <param name="IDCard"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime? getBirthByIDCard(string IDCard)
|
||||
{
|
||||
DateTime? birth = null;
|
||||
if (!string.IsNullOrEmpty(IDCard))
|
||||
{
|
||||
string birthStr = string.Empty;
|
||||
if (IDCard.Length == 18)
|
||||
{
|
||||
birthStr = IDCard.Substring(6, 8).Insert(6, "-").Insert(4, "-");
|
||||
|
||||
}
|
||||
else if (IDCard.Length == 15)
|
||||
{
|
||||
birthStr = IDCard.Substring(6, 6).Insert(4, "-").Insert(2, "-");
|
||||
}
|
||||
|
||||
DateTime time = new DateTime();
|
||||
if (DateTime.TryParse(birthStr, out time))
|
||||
{
|
||||
birth = time;
|
||||
}
|
||||
}
|
||||
|
||||
return birth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取年龄
|
||||
/// </summary>
|
||||
/// <param name="birthDate"></param>
|
||||
/// <param name="now"></param>
|
||||
/// <returns></returns>
|
||||
public static int CalculateAgeCorrect(DateTime birthDate)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
int age = now.Year - birthDate.Year;
|
||||
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;
|
||||
return age;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user