Solved Qt5.6 QDateTime::fromString ERROR
-
Hi,
QDateTime dt=QDateTime::fromString("2016-10-16 00:00:00","yyyy-MM-dd hh:mm:ss");
dt.isValid()==false!!!!
Using Qt5.6, Fedora 17, x86
This is a bug? -
@ReinaldoJr Works for me. Qt 5.6, x86_64 Linux
-
@ReinaldoJr
i just triedQDateTime dateTime2=QDateTime::fromString("2016-10-16 00:00:00","yyyy-MM-dd hh:mm:ss"); bool txt= dateTime2.isValid() ; qDebug()<< "bool" <<txt; bool true;
Works for me as well Qt 5.5.0 ,Kubuntu 14.04
-
Thank you for help
Strangely the error persists ... on different machines (Qt5.6 Fedora 17 x86, Qt5.6 Fedora 17 x64) will install another OS...#include <QCoreApplication> #include <QDateTime> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QDateTime dateTime2=QDateTime::fromString("2016-10-15 00:00:00","yyyy-MM-dd hh:mm:ss"); bool txt=dateTime2.isValid() ; qDebug()<<"Dt0"<< "bool" <<txt; // :-( dateTime2=QDateTime::fromString("2016-10-16 00:00:00","yyyy-MM-dd hh:mm:ss"); txt=dateTime2.isValid() ; qDebug()<<"Dt1"<< "bool" <<txt; // :-( dateTime2=QDateTime::fromString("2016-10-17 00:00:00","yyyy-MM-dd hh:mm:ss"); txt=dateTime2.isValid() ; qDebug()<<"Dt2"<< "bool" <<txt; return a.exec(); }
Result:
Dt0 bool true
Dt1 bool false
Dt2 bool true -
Hi,
Working fine on OS X also.
What timezone are you in ?
-
Hi,
UTC offset (ISO 8601) −03:00 = America/Sao Paulo (LMT)
-
It worked
We use the time the statement(Until then I had never given problem!):
QDateTime dt=QDateTime::fromString("2016-10-16 00:00:00","yyyy-MM-dd hh:mm:ss"); //dt.isvalid=false!!!
So he went back to work:
QDateTime dt=QDateTime::fromString("2016-10-16 00:00:00","yyyy-MM-dd hh:mm:ss"); dt.setTimeSpec(Qt::UTC); //dt.isvalid=true!!! is ok!!!
Thank you all
-
Just building on what others have already said... :)
@ReinaldoJr said:
UTC offset (ISO 8601) −03:00 = America/Sao Paulo (LMT)
Just for clarity, you might be at -03:00 right now, but thanks to daylight savings, you'll jump to -02:00 at "2016-10-16 00:00:00" (local time), which means you're never really at that point in (local) time.
QDateTime | Daylight-Saving Time (DST) says:
QDateTime takes into consideration the Standard Time to Daylight-Saving Time transition. For example if the transition is at 2am and the clock goes forward to 3am, then there is a "missing" hour from 02:00:00 to 02:59:59.999 which QDateTime considers to be invalid. Any date maths performed will take this missing hour into account and return a valid result.
In your case, that "missing hour" is from "2016-10-16 00:00:00" to "2016-10-16 01:00:00".
Depending on what you're trying to do, you should either prevent your users from entering invalid local times, or use UTC as suggested above.
Cheers.
-
In your case, that "missing hour" is from "2016-10-16 00:00:00" to "2016-10-16 01:00:00".
I think the transition is always at 2 AM local time. So you'd always miss 2:00, i.e. the clock jumps from 1:59 to 3:00.
-
@kshegunov said:
I think the transition is always at 2 AM local time.
Not according to http://clock.zone/america/sao-paulo
The timezone America/Sao_Paulo switches to DST on Sunday, 16 October 2016 (12:00 AM). New GMT offset will be GMT-2 hour(s) (BRST). Clocks will be set +1h.
It is always 1am forward, and 2am back where I live :)
Cheers.
-
Huh, this is confusing. Can't they make it the same everywhere ...
EET (+2 UTC), where I live, switches forward at 2 AM local, and I think CET (+1 UTC) also does the same. Anyway, I suppose I'm just wrong in my extrapolation, happens too often I'm afraid ... :)Kind regards.