qt判断两个日期大小不能转成int,因为日期过大时会超出int范围。
int 范围:-2,147,483,648 到 2,147,483,647
uint范围:0~4294967295
int a = 2147483648; qDebug() << a;//-2147483648 QDateTime time = QDateTime::fromTime_t(2147483647); QString dateStr = time.toString("yyyy-MM-dd hh:mm:ss"); qDebug() << dateStr;//"2038-01-19 11:14:07"
int 最大范围值存放以上时间后的值是错误的。
以下为在网上搜到的比较方法:是错误的
错误示范
Qt 可直接将QDateTime转换成相同格式QString进行比较:
QString endDate = date.toString("yyyy-MM-dd"); QString currentDate = QDateTime::currentDateTime().toString("yyyy-MM-dd"); if (endDate < currentDate) { qDebug()<<"已过期"; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)