Qt QDateTime from string with timezone and daylight savingDetermine a user's timezoneHow do I iterate over the words of a string?Daylight saving time and time zone best practicesBuilding TimeZone object in JavaDateTime must contain TimeZone information and take Daylight Savings into accountmoment.js, timezones and daylight savingsTimestamps, Timezones and Daylights SavingsQt5 using daylight savings time for embedded device from NTP server timeDaylight Saving Time start and end dates in Ruby/RailsSpark: converting GMT time stamps to Eastern taking daylight savings into account

Is alignment needed after replacing upper control arms?

Can a PC attack themselves with an unarmed strike?

Whats the name of this projection?

In the movie Harry Potter and the Order or the Phoenix, why didn't Mr. Filch succeed to open the Room of Requirement if it's what he needed?

"How do you solve a problem like Maria?"

Does the United States guarantee any unique freedoms?

Why should I "believe in" weak solutions to PDEs?

How to help new students accept function notation

Is it allowed and safe to carry a passenger / non-pilot in the front seat of a small general aviation airplane?

Will a paper be retracted if a flaw in released software code invalidates its central idea?

Double blind peer review when paper cites author's GitHub repo for code

How would I as a DM create a smart phone-like spell/device my players could use?

How quickly could a country build a tall concrete wall around a city?

What does VB stand for?

In Pokémon Go, why does one of my Pikachu have an option to evolve, but another one doesn't?

Does this put me at risk for identity theft?

Our group keeps dying during the Lost Mine of Phandelver campaign. What are we doing wrong?

Is it true that control+alt+delete only became a thing because IBM would not build Bill Gates a computer with a task manager button?

Need help understanding lens reach

Should I self-publish my novella on Amazon or try my luck getting publishers?

What is the German idiom or expression for when someone is being hypocritical against their own teachings?

French equivalent of "Make leaps and bounds"

Why do private jets such as Gulfstream fly higher than other civilian jets?

Short story about a teenager who has his brain replaced with a microchip (Psychological Horror)



Qt QDateTime from string with timezone and daylight saving


Determine a user's timezoneHow do I iterate over the words of a string?Daylight saving time and time zone best practicesBuilding TimeZone object in JavaDateTime must contain TimeZone information and take Daylight Savings into accountmoment.js, timezones and daylight savingsTimestamps, Timezones and Daylights SavingsQt5 using daylight savings time for embedded device from NTP server timeDaylight Saving Time start and end dates in Ruby/RailsSpark: converting GMT time stamps to Eastern taking daylight savings into account






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















i am inserting time from string



QDateTime time =QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");
qDebug()<<time.toLocalTime().toString();
qDebug()<<time.toUTC().toString();
qDebug()<<time.isDaylightTime();


output i am getting as



  • "Tue Mar 26 23:37:40 2019"

  • "Wed Mar 27 06:37:40 2019 GMT"

  • false

it should have given



  • "Tue Mar 26 23:37:40 2019"

  • "Wed Mar 27 05:37:40 2019 GMT"

  • true

how can i pass daylight saving with the timestamp string?










share|improve this question






























    1















    i am inserting time from string



    QDateTime time =QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");
    qDebug()<<time.toLocalTime().toString();
    qDebug()<<time.toUTC().toString();
    qDebug()<<time.isDaylightTime();


    output i am getting as



    • "Tue Mar 26 23:37:40 2019"

    • "Wed Mar 27 06:37:40 2019 GMT"

    • false

    it should have given



    • "Tue Mar 26 23:37:40 2019"

    • "Wed Mar 27 05:37:40 2019 GMT"

    • true

    how can i pass daylight saving with the timestamp string?










    share|improve this question


























      1












      1








      1








      i am inserting time from string



      QDateTime time =QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");
      qDebug()<<time.toLocalTime().toString();
      qDebug()<<time.toUTC().toString();
      qDebug()<<time.isDaylightTime();


      output i am getting as



      • "Tue Mar 26 23:37:40 2019"

      • "Wed Mar 27 06:37:40 2019 GMT"

      • false

      it should have given



      • "Tue Mar 26 23:37:40 2019"

      • "Wed Mar 27 05:37:40 2019 GMT"

      • true

      how can i pass daylight saving with the timestamp string?










      share|improve this question














      i am inserting time from string



      QDateTime time =QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");
      qDebug()<<time.toLocalTime().toString();
      qDebug()<<time.toUTC().toString();
      qDebug()<<time.isDaylightTime();


      output i am getting as



      • "Tue Mar 26 23:37:40 2019"

      • "Wed Mar 27 06:37:40 2019 GMT"

      • false

      it should have given



      • "Tue Mar 26 23:37:40 2019"

      • "Wed Mar 27 05:37:40 2019 GMT"

      • true

      how can i pass daylight saving with the timestamp string?







      c++ qt timezone dst






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 5:57









      Awais RafiqueAwais Rafique

      4155 silver badges15 bronze badges




      4155 silver badges15 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          2














          If you take a look into the official docs, it says:




          If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always return false.




          So first of all, check that the QDateTime::timeSpec is returning what you expect.



          If you know the format in advance, try to specify the format of the string that you want to parse by using the equivalent function QDateTime::fromString.



          Combining both things you can do something like this:



          const char* s = "2009-11-05T03:54:00";
          QDateTime d = QDateTime::fromString(s, Qt::ISODate).toLocalTime();
          d.setTimeSpec(Qt::LocalTime); // Just to ensure that the time spec are the proper one, i think is not needed
          qDebug() << d.isDaylightTime();





          share|improve this answer


































            2














            First, UTC time "Wed Mar 27 06:37:40 2019 GMT" is definitely right when calculated from "Wed Mar 26 22:37:40 2019 GMT-08". How do you think it could be 5:37?



            Explanation why GMT or UTC doesn't include DST:




            Neither UTC nor GMT ever change for Daylight Saving Time (DST).
            However, some of the countries that use GMT switch to different time
            zones during their DST period. For example, AKDT (Alaska Daylight
            Time) is one of GMT-8 time zones during their DST (summer daylight
            saving time) between 10 March and 3 November in 2019. During the
            winter, AKST (Alaska Standard Time) which is GMT-9 is in use.




            Second, as was already pointed in the other answer time QDateTime::isDaylightTime always returns false if the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone.



            When you use QDateTime::fromString with time zone information as in your code example timespec is correctly set to Qt::OffsetFromUTC. You can instantiate another QDateTime object to the same time but having the TimeSpec as Qt::LocalTime or Qt::TimeZone. You can e.g. convert to local time with QDateTime::toLocalTime or to either Qt::LocalTime or Qt::TimeZone with QDateTime::fromSecsSinceEpoch which accepts offset seconds for time zone.



            See example code below. I'm located in Finland where daylight savings time starts in March 31 so you can see difference of local time when standard time is in use and when daylight time is in use:



            QDateTime time = QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");

            qDebug()<<"nLocal time EET:";
            QDateTime localTime = time.toLocalTime();
            // This works too, here to local time:
            //QDateTime localTime = QDateTime::fromSecsSinceEpoch(time.toSecsSinceEpoch());
            qDebug()<<localTime.timeSpec();
            qDebug()<<localTime.timeZone();
            qDebug()<<localTime.timeZoneAbbreviation();
            qDebug()<<localTime.toLocalTime().toString();
            qDebug()<<localTime.toUTC().toString();
            qDebug()<<localTime.isDaylightTime();

            time = QDateTime::fromString("Wed Apr 26 22:37:40 2019 GMT-08");

            qDebug()<<"nLocal time EEST:";
            localTime = time.toLocalTime();
            qDebug()<<localTime.timeSpec();
            qDebug()<<localTime.timeZone();
            qDebug()<<localTime.timeZoneAbbreviation();
            qDebug()<<localTime.toLocalTime().toString();
            qDebug()<<localTime.toUTC().toString();
            qDebug()<<localTime.isDaylightTime();


            Output:



            Local time EET:
            Qt::LocalTime
            QTimeZone("Europe/Helsinki")
            "EET"
            "Wed Mar 27 08:37:40 2019"
            "Wed Mar 27 06:37:40 2019 GMT"
            false

            Local time EEST:
            Qt::LocalTime
            QTimeZone("Europe/Helsinki")
            "EEST"
            "Sat Apr 27 09:37:40 2019"
            "Sat Apr 27 06:37:40 2019 GMT"
            true





            share|improve this answer



























            • "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

              – Awais Rafique
              Mar 27 at 17:51







            • 1





              I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

              – talamaki
              Mar 27 at 21:34













            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370667%2fqt-qdatetime-from-string-with-timezone-and-daylight-saving%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            If you take a look into the official docs, it says:




            If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always return false.




            So first of all, check that the QDateTime::timeSpec is returning what you expect.



            If you know the format in advance, try to specify the format of the string that you want to parse by using the equivalent function QDateTime::fromString.



            Combining both things you can do something like this:



            const char* s = "2009-11-05T03:54:00";
            QDateTime d = QDateTime::fromString(s, Qt::ISODate).toLocalTime();
            d.setTimeSpec(Qt::LocalTime); // Just to ensure that the time spec are the proper one, i think is not needed
            qDebug() << d.isDaylightTime();





            share|improve this answer































              2














              If you take a look into the official docs, it says:




              If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always return false.




              So first of all, check that the QDateTime::timeSpec is returning what you expect.



              If you know the format in advance, try to specify the format of the string that you want to parse by using the equivalent function QDateTime::fromString.



              Combining both things you can do something like this:



              const char* s = "2009-11-05T03:54:00";
              QDateTime d = QDateTime::fromString(s, Qt::ISODate).toLocalTime();
              d.setTimeSpec(Qt::LocalTime); // Just to ensure that the time spec are the proper one, i think is not needed
              qDebug() << d.isDaylightTime();





              share|improve this answer





























                2












                2








                2







                If you take a look into the official docs, it says:




                If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always return false.




                So first of all, check that the QDateTime::timeSpec is returning what you expect.



                If you know the format in advance, try to specify the format of the string that you want to parse by using the equivalent function QDateTime::fromString.



                Combining both things you can do something like this:



                const char* s = "2009-11-05T03:54:00";
                QDateTime d = QDateTime::fromString(s, Qt::ISODate).toLocalTime();
                d.setTimeSpec(Qt::LocalTime); // Just to ensure that the time spec are the proper one, i think is not needed
                qDebug() << d.isDaylightTime();





                share|improve this answer















                If you take a look into the official docs, it says:




                If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always return false.




                So first of all, check that the QDateTime::timeSpec is returning what you expect.



                If you know the format in advance, try to specify the format of the string that you want to parse by using the equivalent function QDateTime::fromString.



                Combining both things you can do something like this:



                const char* s = "2009-11-05T03:54:00";
                QDateTime d = QDateTime::fromString(s, Qt::ISODate).toLocalTime();
                d.setTimeSpec(Qt::LocalTime); // Just to ensure that the time spec are the proper one, i think is not needed
                qDebug() << d.isDaylightTime();






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 28 at 7:04









                Awais Rafique

                4155 silver badges15 bronze badges




                4155 silver badges15 bronze badges










                answered Mar 27 at 8:07









                mohaboujemohabouje

                2,8121 gold badge10 silver badges24 bronze badges




                2,8121 gold badge10 silver badges24 bronze badges


























                    2














                    First, UTC time "Wed Mar 27 06:37:40 2019 GMT" is definitely right when calculated from "Wed Mar 26 22:37:40 2019 GMT-08". How do you think it could be 5:37?



                    Explanation why GMT or UTC doesn't include DST:




                    Neither UTC nor GMT ever change for Daylight Saving Time (DST).
                    However, some of the countries that use GMT switch to different time
                    zones during their DST period. For example, AKDT (Alaska Daylight
                    Time) is one of GMT-8 time zones during their DST (summer daylight
                    saving time) between 10 March and 3 November in 2019. During the
                    winter, AKST (Alaska Standard Time) which is GMT-9 is in use.




                    Second, as was already pointed in the other answer time QDateTime::isDaylightTime always returns false if the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone.



                    When you use QDateTime::fromString with time zone information as in your code example timespec is correctly set to Qt::OffsetFromUTC. You can instantiate another QDateTime object to the same time but having the TimeSpec as Qt::LocalTime or Qt::TimeZone. You can e.g. convert to local time with QDateTime::toLocalTime or to either Qt::LocalTime or Qt::TimeZone with QDateTime::fromSecsSinceEpoch which accepts offset seconds for time zone.



                    See example code below. I'm located in Finland where daylight savings time starts in March 31 so you can see difference of local time when standard time is in use and when daylight time is in use:



                    QDateTime time = QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EET:";
                    QDateTime localTime = time.toLocalTime();
                    // This works too, here to local time:
                    //QDateTime localTime = QDateTime::fromSecsSinceEpoch(time.toSecsSinceEpoch());
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();

                    time = QDateTime::fromString("Wed Apr 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EEST:";
                    localTime = time.toLocalTime();
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();


                    Output:



                    Local time EET:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EET"
                    "Wed Mar 27 08:37:40 2019"
                    "Wed Mar 27 06:37:40 2019 GMT"
                    false

                    Local time EEST:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EEST"
                    "Sat Apr 27 09:37:40 2019"
                    "Sat Apr 27 06:37:40 2019 GMT"
                    true





                    share|improve this answer



























                    • "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

                      – Awais Rafique
                      Mar 27 at 17:51







                    • 1





                      I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

                      – talamaki
                      Mar 27 at 21:34















                    2














                    First, UTC time "Wed Mar 27 06:37:40 2019 GMT" is definitely right when calculated from "Wed Mar 26 22:37:40 2019 GMT-08". How do you think it could be 5:37?



                    Explanation why GMT or UTC doesn't include DST:




                    Neither UTC nor GMT ever change for Daylight Saving Time (DST).
                    However, some of the countries that use GMT switch to different time
                    zones during their DST period. For example, AKDT (Alaska Daylight
                    Time) is one of GMT-8 time zones during their DST (summer daylight
                    saving time) between 10 March and 3 November in 2019. During the
                    winter, AKST (Alaska Standard Time) which is GMT-9 is in use.




                    Second, as was already pointed in the other answer time QDateTime::isDaylightTime always returns false if the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone.



                    When you use QDateTime::fromString with time zone information as in your code example timespec is correctly set to Qt::OffsetFromUTC. You can instantiate another QDateTime object to the same time but having the TimeSpec as Qt::LocalTime or Qt::TimeZone. You can e.g. convert to local time with QDateTime::toLocalTime or to either Qt::LocalTime or Qt::TimeZone with QDateTime::fromSecsSinceEpoch which accepts offset seconds for time zone.



                    See example code below. I'm located in Finland where daylight savings time starts in March 31 so you can see difference of local time when standard time is in use and when daylight time is in use:



                    QDateTime time = QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EET:";
                    QDateTime localTime = time.toLocalTime();
                    // This works too, here to local time:
                    //QDateTime localTime = QDateTime::fromSecsSinceEpoch(time.toSecsSinceEpoch());
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();

                    time = QDateTime::fromString("Wed Apr 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EEST:";
                    localTime = time.toLocalTime();
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();


                    Output:



                    Local time EET:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EET"
                    "Wed Mar 27 08:37:40 2019"
                    "Wed Mar 27 06:37:40 2019 GMT"
                    false

                    Local time EEST:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EEST"
                    "Sat Apr 27 09:37:40 2019"
                    "Sat Apr 27 06:37:40 2019 GMT"
                    true





                    share|improve this answer



























                    • "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

                      – Awais Rafique
                      Mar 27 at 17:51







                    • 1





                      I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

                      – talamaki
                      Mar 27 at 21:34













                    2












                    2








                    2







                    First, UTC time "Wed Mar 27 06:37:40 2019 GMT" is definitely right when calculated from "Wed Mar 26 22:37:40 2019 GMT-08". How do you think it could be 5:37?



                    Explanation why GMT or UTC doesn't include DST:




                    Neither UTC nor GMT ever change for Daylight Saving Time (DST).
                    However, some of the countries that use GMT switch to different time
                    zones during their DST period. For example, AKDT (Alaska Daylight
                    Time) is one of GMT-8 time zones during their DST (summer daylight
                    saving time) between 10 March and 3 November in 2019. During the
                    winter, AKST (Alaska Standard Time) which is GMT-9 is in use.




                    Second, as was already pointed in the other answer time QDateTime::isDaylightTime always returns false if the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone.



                    When you use QDateTime::fromString with time zone information as in your code example timespec is correctly set to Qt::OffsetFromUTC. You can instantiate another QDateTime object to the same time but having the TimeSpec as Qt::LocalTime or Qt::TimeZone. You can e.g. convert to local time with QDateTime::toLocalTime or to either Qt::LocalTime or Qt::TimeZone with QDateTime::fromSecsSinceEpoch which accepts offset seconds for time zone.



                    See example code below. I'm located in Finland where daylight savings time starts in March 31 so you can see difference of local time when standard time is in use and when daylight time is in use:



                    QDateTime time = QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EET:";
                    QDateTime localTime = time.toLocalTime();
                    // This works too, here to local time:
                    //QDateTime localTime = QDateTime::fromSecsSinceEpoch(time.toSecsSinceEpoch());
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();

                    time = QDateTime::fromString("Wed Apr 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EEST:";
                    localTime = time.toLocalTime();
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();


                    Output:



                    Local time EET:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EET"
                    "Wed Mar 27 08:37:40 2019"
                    "Wed Mar 27 06:37:40 2019 GMT"
                    false

                    Local time EEST:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EEST"
                    "Sat Apr 27 09:37:40 2019"
                    "Sat Apr 27 06:37:40 2019 GMT"
                    true





                    share|improve this answer















                    First, UTC time "Wed Mar 27 06:37:40 2019 GMT" is definitely right when calculated from "Wed Mar 26 22:37:40 2019 GMT-08". How do you think it could be 5:37?



                    Explanation why GMT or UTC doesn't include DST:




                    Neither UTC nor GMT ever change for Daylight Saving Time (DST).
                    However, some of the countries that use GMT switch to different time
                    zones during their DST period. For example, AKDT (Alaska Daylight
                    Time) is one of GMT-8 time zones during their DST (summer daylight
                    saving time) between 10 March and 3 November in 2019. During the
                    winter, AKST (Alaska Standard Time) which is GMT-9 is in use.




                    Second, as was already pointed in the other answer time QDateTime::isDaylightTime always returns false if the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone.



                    When you use QDateTime::fromString with time zone information as in your code example timespec is correctly set to Qt::OffsetFromUTC. You can instantiate another QDateTime object to the same time but having the TimeSpec as Qt::LocalTime or Qt::TimeZone. You can e.g. convert to local time with QDateTime::toLocalTime or to either Qt::LocalTime or Qt::TimeZone with QDateTime::fromSecsSinceEpoch which accepts offset seconds for time zone.



                    See example code below. I'm located in Finland where daylight savings time starts in March 31 so you can see difference of local time when standard time is in use and when daylight time is in use:



                    QDateTime time = QDateTime::fromString("Wed Mar 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EET:";
                    QDateTime localTime = time.toLocalTime();
                    // This works too, here to local time:
                    //QDateTime localTime = QDateTime::fromSecsSinceEpoch(time.toSecsSinceEpoch());
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();

                    time = QDateTime::fromString("Wed Apr 26 22:37:40 2019 GMT-08");

                    qDebug()<<"nLocal time EEST:";
                    localTime = time.toLocalTime();
                    qDebug()<<localTime.timeSpec();
                    qDebug()<<localTime.timeZone();
                    qDebug()<<localTime.timeZoneAbbreviation();
                    qDebug()<<localTime.toLocalTime().toString();
                    qDebug()<<localTime.toUTC().toString();
                    qDebug()<<localTime.isDaylightTime();


                    Output:



                    Local time EET:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EET"
                    "Wed Mar 27 08:37:40 2019"
                    "Wed Mar 27 06:37:40 2019 GMT"
                    false

                    Local time EEST:
                    Qt::LocalTime
                    QTimeZone("Europe/Helsinki")
                    "EEST"
                    "Sat Apr 27 09:37:40 2019"
                    "Sat Apr 27 06:37:40 2019 GMT"
                    true






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 29 at 7:39

























                    answered Mar 27 at 9:33









                    talamakitalamaki

                    3,2221 gold badge17 silver badges31 bronze badges




                    3,2221 gold badge17 silver badges31 bronze badges















                    • "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

                      – Awais Rafique
                      Mar 27 at 17:51







                    • 1





                      I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

                      – talamaki
                      Mar 27 at 21:34

















                    • "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

                      – Awais Rafique
                      Mar 27 at 17:51







                    • 1





                      I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

                      – talamaki
                      Mar 27 at 21:34
















                    "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

                    – Awais Rafique
                    Mar 27 at 17:51






                    "Wed Mar 26 22:37:40 2019 GMT-08" include the daylight saving hour, and i have also checked on the google it was showing 5:37

                    – Awais Rafique
                    Mar 27 at 17:51





                    1




                    1





                    I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

                    – talamaki
                    Mar 27 at 21:34





                    I updated my answer with explanation of GMT not including daylight saving time. I used Alaska which is currently in GMT-8 as an example. Hope it clarifies.

                    – talamaki
                    Mar 27 at 21:34

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370667%2fqt-qdatetime-from-string-with-timezone-and-daylight-saving%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현