簡書

C# 根据出生日期(年月日)计算年龄
public int GetAgeByBirthdate(DateTime birthdate){ DateTi...
扫描右侧二维码阅读全文
24
2021/02

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

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://vtzw.com/post/604.html

Last modification:December 31st, 2021 at 03:30 pm

Leave a Comment