Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5.6 QDateTime::fromString ERROR
Forum Updated to NodeBB v4.3 + New Features

Qt5.6 QDateTime::fromString ERROR

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 6 Posters 3.7k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R ReinaldoJr

    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?

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #2

    @ReinaldoJr Works for me. Qt 5.6, x86_64 Linux

    1 Reply Last reply
    0
    • R ReinaldoJr

      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?

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #3

      @ReinaldoJr
      i just tried

          QDateTime 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

      --Alles ist gut.

      1 Reply Last reply
      1
      • R Offline
        R Offline
        ReinaldoJr
        wrote on last edited by
        #4

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Hi,

          Working fine on OS X also.

          What timezone are you in ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ReinaldoJr
            wrote on last edited by
            #6

            Hi,

            UTC offset (ISO 8601) −03:00 = America/Sao Paulo (LMT)

            1 Reply Last reply
            0
            • R Offline
              R Offline
              ReinaldoJr
              wrote on last edited by ReinaldoJr
              #7

              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

              1 Reply Last reply
              0
              • Paul ColbyP Offline
                Paul ColbyP Offline
                Paul Colby
                wrote on last edited by
                #8

                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.

                kshegunovK 1 Reply Last reply
                1
                • Paul ColbyP Paul Colby

                  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.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #9

                  @Paul-Colby

                  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.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • Paul ColbyP Offline
                    Paul ColbyP Offline
                    Paul Colby
                    wrote on last edited by
                    #10

                    @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.

                    kshegunovK 1 Reply Last reply
                    0
                    • Paul ColbyP Paul Colby

                      @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.

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #11

                      @Paul-Colby

                      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.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved