QDateTime::fromMSecsSinceEpoch not works correctly

I'm trying to convert this value (1426519114913) that is a unix timestamp, to QDateTime object. for doing this we have fromMSecsSinceEpoch function in QDateTime that converts msecs from epoch to DateTime object. but I was unsuccessfull, for testing I do below test that it shows me that there is maybe an error with qt, am I forget something? please help me.

quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
QDateTime dt3 = QDateTime::fromMSecsSinceEpoch(timestamp);

Edit: The Error was with debugger's locals window, that now shown the correct date value after converting. actually results are correct. just needed to toString() to see date in correct format. Thanks for everyone.


There is nothing wrong with that code. The result looks right!

#include <QDateTime>
//...
QDateTime tpast = QDateTime::fromMSecsSinceEpoch(1426519114913);
quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
QDateTime dt3 = QDateTime::fromMSecsSinceEpoch(timestamp);

qDebug() << "time(1426519114913):" << tpast.toString();
qDebug() << "timestamp:" << timestamp;
qDebug() << "time(timestamp):" << dt3.toString();

/*
output:
time(1426519114913): "Mon Mar 16 11:18:34 2015"
timestamp: 1427073124768
time(timestamp): "Sun Mar 22 21:12:04 2015"
*/
链接地址: http://www.djcxy.com/p/25066.html

上一篇: 使用mysql中的alter table将日期转换为日期时间或时间戳

下一篇: QDateTime :: fromMSecsSinceEpoch无法正常工作