[solved] QDateTime::fromString missing seconds.
General and Desktop
8
Posts
3
Posters
2.3k
Views
1
Watching
-
When running the following code in Qt 5.4.1 mingw Win7x64.
QString bLine("2015-06-03T12.20.55Z"); QDateTime begintime = QDateTime::fromString(bLine, Qt::ISODate); qDebug() << bLine << " --> " << begintime.toString(Qt::ISODate);
I get weird results.
"2015-06-03T12.20.55Z" --> "2015-06-03T12:20:33Z"
Where did the 22 seconds go? Leap seconds?
-
No way.
"2015-06-03T12.20.99Z" --> "2015-06-03T12:20:59Z"
So this is an bug right? Since ISO 8601 uses 0-59+1 (for leap seconds) and not 0-99.
The Qdocu says "the second with a leading zero (00 to 59)" for ss.
Workaround:QString bLine("2015-06-03T12.20.30Z"); QString format("yyyy-MM-ddThh.mm.ssZ"); QDateTime begintime = QDateTime::fromString(bLine, format); qDebug() << bLine << " --> " << begintime.toString(Qt::ISODate);
However, that will fail on leap seconds. Which I don't need... yet...
-
@Jeroen3 please use the proper time format separator which is a colon (:)
-
@Jeroen3 please use the proper time format separator which is a colon (:)
@Pablo-J.-Rogina Yes I will QString::replace . for : (a colon).
Since the filename timestamp and file content timestamp are created using the same routine on an proprietary platform I cannot use a colon initially.