正在浏览:C#/dotnet

C#根据生日计算年龄的方法: var today = DateTime.Today;//当前日期var age = today.Year – birthdate.Year;//计算年龄// 判断生日是否已过,返回准确年龄if (birthdate today.AddYears(-age)) age–;