DateTime
代表一个人的生日,我该如何计算他们的年龄?
发布于 2018-08-10 14:00:34
简单易懂的解决方案。
// Save today's date.
var today = DateTime.Today;
// Calculate the age.
var age = today.Year - birthdate.Year;
// Go back to the year the person was born in case of a leap year
if (birthdate > today.AddYears(-age)) age--;
但是,这假设你正在寻找西式年龄观念和不使用East Asian reckoning(https://en.wikipedia.org/wiki/East_Asian_age_reckoning。
https://stackoverflow.com/questions/-100000540
复制相似问题