Parse QDateTime from string
-
wrote on 11 Aug 2021, 07:35 last edited by
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?
-
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
-
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?
wrote on 11 Aug 2021, 07:49 last edited by@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.
-
wrote on 11 Aug 2021, 14:42 last edited by
@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();
1/4