QDateTime::fromString wrong result...
-
I want to convert the date time string to a date, I am doing this:
QDateTime dtToSet(QDateTime::fromString("2022-04-26 15:02:00", "yyyy-MM-dd HH:mm:ss"));
I've done quite a few searches online and from what I can see the syntax and formatting options are correct, but from the above the date in the debugger dtToSet shows as:
Fri Jun 5 00:00:00 143463
Why ?
-
Ok, so I added the following:
const QDate cdtTemp(dtToSet.date()); const QDate ctmTemp(dtToSet.time());
cdtTemp contains Tue Apr 26 2022
ctmTemp contains 15:02:00So there is nothing wrong with the code its just an order display of dtToSet being incorrect in the Qt Creator debugger.
-
@SPlatten said in QDateTime::fromString wrong result...:
Why ?
Because your output is not what you save into dtToSet. Please show the full code.
-
Ok, so I added the following:
const QDate cdtTemp(dtToSet.date()); const QDate ctmTemp(dtToSet.time());
cdtTemp contains Tue Apr 26 2022
ctmTemp contains 15:02:00So there is nothing wrong with the code its just an order display of dtToSet being incorrect in the Qt Creator debugger.