// 获取身份证中的生日
public DateTime getBirthDay_From_IDCARD(string strIDCARD)
{
DateTime dtBirthday = new DateTime();
dtBirthday = DateTime.Now;
try
{
string strY, strM, strD, strSystime;
//获取生日
if (strIDCARD.Length == 15)
{
strY = "19" strIDCARD.Substring(6, 2);
strM = strIDCARD.Substring(8, 2);
strD = strIDCARD.Substring(10, 2);
strSystime = strY "-" strM "-" strD;
dtBirthday = DateTime.Parse(strSystime);
}
else if (strIDCARD.Length == 18)
{
strY = strIDCARD.Substring(6, 4);
strM = strIDCARD.Substring(10, 2);
strD = strIDCARD.Substring(12, 2);
strSystime = strY "-" strM "-" strD;
dtBirthday = DateTime.Parse(strSystime);
}
else
{
MessageBox.Show("请检查身份证位数是否正确?");
}
} // try end
catch (Exception hex)
{
LogUtil.LogError(hex);
//MessageBox.Show("根据员工ID 找出 员工姓名 错误 !");
} // catch end
return dtBirthday;
}// FUNCATION END
评论