下边代码段是关于C#根据出生日期计算年龄的的代码,应该能对小伙伴们有些用途。
public int CalculateAgeCorrect(DateTime birthDate, DateTime now)
{
int age = now.Year - birthDate.Year;
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age–;
return age;
}