首页 > 代码库 > C#根据出生日期计算年龄

C#根据出生日期计算年龄

public int CalculateAge(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;
        }

C#根据出生日期计算年龄