Your input is not what you think it is.
#include <QCoreApplication>
#include <QDateTime>
#include <QStringList>
#include <QDebug>
int main(int argc, char **argv) {
// Mimics your reading via std::string
std::string str("2013-10-14 23:59:59,some,other,stuff");
timestampH.setTimeSpec(Qt::UTC);
qDebug() << timestampH << timestampH.toString(Qt::ISODate) << timestampH.isNull();
return 0;
}
#include <QCoreApplication>
#include <QDateTime>
#include <QStringList>
#include <QDebug>
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
// Mimics your reading via std::string
std::string str("2013-10-14 23:59:59,some,other,stuff");
QString row = QString::fromLocal8Bit(str.c_str());
QStringList rowVec = row.split(",");
QString timestamp = rowVec.at(0);
QDateTime timestampH = QDateTime::fromString(timestamp,"yyyy-MM-dd HH:mm:ss");
timestampH.setTimeSpec(Qt::UTC);
qDebug() << timestampH << timestampH.toString(Qt::ISODate) << timestampH.isNull();
return 0;
}
To copy to clipboard, switch view to plain text mode
Output:
QDateTime("Mon Oct 14 23:59:59 2013") "2013-10-14T23:59:59Z" false
QDateTime("Mon Oct 14 23:59:59 2013") "2013-10-14T23:59:59Z" false
To copy to clipboard, switch view to plain text mode
Bookmarks