C#通过身份证号取年龄
public static DateTime IdCardtoDate(this string cardno) { try { if (string.IsNullOrWhiteSpace(cardno) || cardno.Length != 18) { return new DateTime(2099, 1, 1); } else { int year = Convert.ToInt32(cardno.Substring(6, 4)); int month = Convert.ToInt32(cardno.Substring(10, 2)); int day = Convert.ToInt32(cardno.Substring(12, 2)); return new DateTime(year, month, day); } } catch { return new DateTime(2099, 1, 1); } }
微信扫码查看本文
发表评论