给定一个代表某人生日的 DateTime
,我如何计算他们的年龄?
最佳答案
一个易于理解和简单的解决方案。
// Save today's date.
var today = DateTime.Today;
// Calculate the age.
var age = today.Year - birthdate.Year;
// Go back to the year in which the person was born in case of a leap year
if (birthdate.Date > today.AddYears(-age)) age--;
但是,这假设您正在寻找关于时代的西方观念,而不是使用 East Asian reckoning .
关于c# - 如何根据 DateTime 类型的生日计算某人的年龄?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9/