/// <summary>
/// 根据年龄获得年龄段
/// </summary>
/// <param name="age"></param>
/// <returns></returns>
public static string GetAgeRange(int age)
{
int year = DateTime.Now.Year - age;
if (year <= || year > DateTime.Now.Year)
{
return "";
}
string thirdNum= year.ToString().Substring(, );
string fourthNum = year.ToString().Substring(, );
if (int.Parse(fourthNum) >= )
{
return string.Format("{0}{1}后", thirdNum, "");
}
else
{
return string.Format("{0}{1}后", thirdNum, "");
}
}
/// <summary>
/// 根据身份证获得年龄段
/// </summary>
/// <param name="IDCard"></param>
/// <returns></returns>
public static string GetAgeRange(string IDCard)
{
DateTime birth = ValidatHelper.GetBirthByIDCard(IDCard);
string year = birth.Year.ToString().PadLeft(, '');
string thirdNum= year.ToString().Substring(, );
string fourthNum= year.ToString().Substring(, );
if (int.Parse(y2) >= )
{
return string.Format("{0}{1}后", thirdNum, "");
}
else
{
return string.Format("{0}{1}后", thirdNum, "");
}
}
#region 通过身份证号获得出生日期
public static DateTime GetBirthByIDCard(string IDCard)
{
if (!CheckIDCard(IDCard))
{
return DateTime.MinValue.Date;
}
string birth = "";
if (IDCard.Length == )
{
birth = IDCard.Substring(, ).Insert(, "-").Insert(, "-");
}
else if (IDCard.Length == )
{
birth = IDCard.Substring(, ).Insert(, "-").Insert(, "-");
}
DateTime time = new DateTime();
if (DateTime.TryParse(birth, out time) == true)
{
return time;
}
else
{
return DateTime.MinValue.Date;
}
}
#endregion