只是补充一下,UTC似乎在惹你生气。检查输出的最后一行:
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv );
QDateTime test1;
test1.setTime_t(25);
qDebug() << "Local 1: " << test1.toString("hh:mm:ss");
qDebug() << "Local 1: " << test1.toString();
qDebug() << "UTC 1: " << test1.toUTC().toString();
QDateTime test2;
test2.setDate(QDate(1970,01,01));
test2.setTime(QTime(00,59));
qDebug() << "Local 2: " << test2.toString("hh:mm:ss");
qDebug() << "Local 2: " << test2.toString();
qDebug() << "UTC 2: " << test2.toUTC().toString();
return 0;
}
输出:
Local 1: "01:00:25"
Local 1: "Thu Jan 1 01:00:25 1970"
UTC 1: "Thu Jan 1 00:00:25 1970"
Local 2: "00:59:00"
Local 2: "Thu Jan 1 00:59:00 1970"
UTC 2: "Wed Dec 31 23:59:00 1969"
PS:我在UTC + 1