Parse QDateTime from string
-
Hi,
I would like to init object of class QDateTime with string like this
QString line = "29/04/2021,13:42:12.051000"; QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzzzz"); qDebug()<<dateTime.toString();
But in result i got empty string
""
How could I parse string?
-
@Creatorczyk
I don't think you can with 5z's as your milliseconds
Time only supports
so you'll have to truncate the string
-
@Creatorczyk the "z" is related to the number of milliseconds so "z", "zz" and "zzz" make sense but more not since for example "1" equals "100" milliseconds, "11" equals "110" milliseconds but "1111" exceeds millisecond.
-
@Creatorczyk said in Parse QDateTime from string:
QString line = "29/04/2021,13:42:12.051000";
QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzzzz");
qDebug()<<dateTime.toString();you should shorten the text: 3 characters after "."
QString line = "29/04/2021,13:42:12.051";
QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzz");
qDebug()<<dateTime.toString();