类别:程序开发

日期:2021-02-25 浏览:2050 评论:0

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;
}


本文标题:C# 根据出生日期(年月日)计算年龄
本文链接:https://vtzw.com/post/604.html
作者授权:除特别说明外,本文由 零一 原创编译并授权 零一的世界 刊载发布。
版权声明:本文不使用任何协议授权,您可以任何形式自由转载或使用。
 您阅读本篇文章共花了: 

 可能感兴趣的文章

评论区

发表评论 / 取消回复

必填

选填

选填

◎欢迎讨论,请在这里发表您的看法及观点。