我有一个生日存储为QDate,我想知道这个人有多少年。
我已经尝试过daysTo()函数,但是几年来我无法转换天。
我该怎么做?
发布于 2022-07-11 10:36:00
你可能会想这样做:
int age(const QDate &birthday)
{
const auto today = QDate::currentDate();
auto age = today.year() - birthday.year();
return today.month() >= birthday.month() && today.day() >= birthday.day() ? age : age - 1;
}https://stackoverflow.com/questions/72937059
复制相似问题