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;
} 复制代码
下边代码段是关于C#根据出生日期计算年龄的的代码,应该能对小伙伴们有些用途。
转载于:https://juejin.im/post/5ccfa3baf265da034c703c51