This works for me
#include <QDateTime>
#include <QDebug>
int main()
{
const QString format
= "yyyy-MM-dd hh:mm:ss";
const QString formatted
= d.
toString(format
);
qDebug() << "d=" << d << ", formatted=" << formatted;
qDebug() << "d2=" << d2;
return 0;
}
#include <QDateTime>
#include <QDebug>
int main()
{
QDateTime d = QDateTime::currentDateTime();
const QString format = "yyyy-MM-dd hh:mm:ss";
const QString formatted = d.toString(format);
qDebug() << "d=" << d << ", formatted=" << formatted;
QDateTime d2 = QDateTime::fromString(formatted, format);
qDebug() << "d2=" << d2;
return 0;
}
To copy to clipboard, switch view to plain text mode
Output is
d
= QDateTime(2016-09
-04
18:51:28.549 CEST Qt
::TimeSpec(LocalTime)) , formatted
= "2016-09-04 18:51:28"d2
= QDateTime(2016-09
-04
18:51:28.000 CEST Qt
::TimeSpec(LocalTime))
d= QDateTime(2016-09-04 18:51:28.549 CEST Qt::TimeSpec(LocalTime)) , formatted= "2016-09-04 18:51:28"
d2= QDateTime(2016-09-04 18:51:28.000 CEST Qt::TimeSpec(LocalTime))
To copy to clipboard, switch view to plain text mode
Qt 5.5.1, Debian/Unstable
Cheers,
_
Bookmarks