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. Get datetime in my timezone
Forum Updated to NodeBB v4.3 + New Features

Get datetime in my timezone

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 1.0k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    QDateTime::toTimeSpec has an example.

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

    H 1 Reply Last reply
    2
    • SGaistS SGaist

      QDateTime::toTimeSpec has an example.

      H Offline
      H Offline
      hbatalha
      wrote on last edited by
      #5

      @SGaist But still can't see where I would set the time zone I want in order to do the conversion. For example if someone who is using my app is in China, I need to convert his local time to my local time because China is several hours ahead of my local time. China is 7 hours, if I am not mistaken, ahead, so if a user is using my app there and it is 20:21 there I need the app to update to database the time 11:21.
      For the time being I am using www.timeapi.io api to get time I need.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #6

        The use QDateTime::toTimeZone() - it's even mentioned in toTimeSpec()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        H 1 Reply Last reply
        3
        • Christian EhrlicherC Christian Ehrlicher

          The use QDateTime::toTimeZone() - it's even mentioned in toTimeSpec()

          H Offline
          H Offline
          hbatalha
          wrote on last edited by
          #7

          @Christian-Ehrlicher Thanks, exactly what I needed, my eyes went only for the code, didn't even see QDateTime::toTimeZone() .

          Is there any chance, if you know, that this might not work correctly or it being unreliable when compared to the timeapi.io api?

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

            What kind of unreliability are you expecting ?

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

            H 1 Reply Last reply
            2
            • SGaistS SGaist

              What kind of unreliability are you expecting ?

              H Offline
              H Offline
              hbatalha
              wrote on last edited by
              #9

              @SGaist like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.

              Christian EhrlicherC 1 Reply Last reply
              0
              • H hbatalha

                @SGaist like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @hbatalha said in Get datetime in my timezone:

                like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.

                Nice joke... how is any program supposed to do a correct conversion then?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

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

                  If you are worried about that kind of issue you should do the work server side. Provided that your server time is accurate.

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

                  H 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @hbatalha said in Get datetime in my timezone:

                    like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.

                    Nice joke... how is any program supposed to do a correct conversion then?

                    H Offline
                    H Offline
                    hbatalha
                    wrote on last edited by
                    #12

                    @Christian-Ehrlicher hahaha I don't know, I always find myself going to the worst case scenarios.

                    And also, from time to time my Windows 10 system time changes by itself(always one hour ahead) whether it is set automatically or not and that is an issue many users complain about. So that one thing I am worried about.

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      If you are worried about that kind of issue you should do the work server side. Provided that your server time is accurate.

                      H Offline
                      H Offline
                      hbatalha
                      wrote on last edited by
                      #13

                      @SGaist I am thinking about using an api - http://www.timeapi.io/

                      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