发布于2016年07月1日2017年08月7日 由Mr.RenC#计算年龄的代码实现 在实际开发中有时会根据生日 DateTime 即出生年月日计算出现在的年龄,可以使用下面的代码快速实现。 C# // 当前日期. var today = DateTime.Today; // 计算年龄. var age = today.Year - birthdate.Year; // 判断生日是否已过,返回真实年龄 if (birthdate > today.AddYears(-age)) age--; 123456 // 当前日期.var today = DateTime.Today;// 计算年龄.var age = today.Year - birthdate.Year;// 判断生日是否已过,返回真实年龄if (birthdate > today.AddYears(-age)) age--; 更多推荐阅读:html5 localstorage能存多少数据最简单的Javascript邮箱验证方法树莓派搭建Nginx+PHP服务器Local Storage与Cookies对比HTML标签列表(含HTML5标签)18条你不知道的JavaScript简写语法