public int GetAgeByBirthdate(DateTime birthdate) { DateTime now = DateTime.Now; int age = now.Year - birthdate.Year; if (now.Month < birthdate.Month || (now.Month == birthdate.Month && now.Day < birthdate.Day)) { age--; } return age < 0 ? 0 : age; }
public int GetAgeByBirthdate(DateTime birthdate) { DateTime now = DateTime.Now; int age = now.Year - birthdate.Year; if (now.Month < birthdate.Month || (now.Month == birthdate.Month && now.Day < birthdate.Day)) { age--; } return age < 0 ? 0 : age; }
转载于:https://www.cnblogs.com/aaronguo/p/10701439.html