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. How get list all time zone?
Forum Updated to NodeBB v4.3 + New Features

How get list all time zone?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 2.4k Views
  • 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi.
    How get list all time zone with name and time?
    It is:

    QTimeZone::availableTimeZoneIds();
    

    return name time zone without time.

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

      So hard to read the documentation?

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

      ODБOïO M 2 Replies Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        So hard to read the documentation?

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        hi @Mikeeeeee
        you can use this method https://doc.qt.io/qt-5/qdatetime.html#QDateTime-4

        M 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          So hard to read the documentation?

          M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by
          #4

          @Christian-Ehrlicher said in How get list all time zone?:

          read the documentation?

          Very funny. In the documentation, I found only one suitable method and that one works poorly.

          JonBJ 1 Reply Last reply
          -1
          • ODБOïO ODБOï

            hi @Mikeeeeee
            you can use this method https://doc.qt.io/qt-5/qdatetime.html#QDateTime-4

            M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #5

            @LeLev said in How get list all time zone?:

            method https://doc.qt.io/qt-5/qdatetime.html#QDateTime-4

            this method will not help to get a list of all time zones.

            ODБOïO 1 Reply Last reply
            0
            • M Mikeeeeee

              @Christian-Ehrlicher said in How get list all time zone?:

              read the documentation?

              Very funny. In the documentation, I found only one suitable method and that one works poorly.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Mikeeeeee said in How get list all time zone?:

              Very funny. In the documentation, I found only one suitable method and that one works poorly.

              What "works poorly"? I see https://doc.qt.io/qt-5/qtimezone.html#availableTimeZoneIds to get a list of the ids, https://doc.qt.io/qt-5/qtimezone.html#QTimeZone-1 to create a QTimeZone off each of the available ids, and from the instance there is https://doc.qt.io/qt-5/qtimezone.html#displayName for the name and some other method for whatever you mean by "time", e,.g, https://doc.qt.io/qt-5/qtimezone.html#offsetFromUtc. So what does not work or is not in the documentation?

              M 1 Reply Last reply
              5
              • M Mikeeeeee

                @LeLev said in How get list all time zone?:

                method https://doc.qt.io/qt-5/qdatetime.html#QDateTime-4

                this method will not help to get a list of all time zones.

                ODБOïO Offline
                ODБOïO Offline
                ODБOï
                wrote on last edited by
                #7

                @Mikeeeeee said in How get list all time zone?:

                this method will not help

                    QList<QByteArray> timeZoneIds  = QTimeZone::availableTimeZoneIds();
                    
                    QDateTime localDateTime (QDate::currentDate(), QTime::currentTime());
                   
                    for (int i = 0; i<timeZoneIds.length(); i++){
                            QDateTime dt =  localDateTime.toTimeZone(QTimeZone(timeZoneIds.at(i)));
                            qDebug()<<dt;
                    }
                
                1 Reply Last reply
                2
                • JonBJ JonB

                  @Mikeeeeee said in How get list all time zone?:

                  Very funny. In the documentation, I found only one suitable method and that one works poorly.

                  What "works poorly"? I see https://doc.qt.io/qt-5/qtimezone.html#availableTimeZoneIds to get a list of the ids, https://doc.qt.io/qt-5/qtimezone.html#QTimeZone-1 to create a QTimeZone off each of the available ids, and from the instance there is https://doc.qt.io/qt-5/qtimezone.html#displayName for the name and some other method for whatever you mean by "time", e,.g, https://doc.qt.io/qt-5/qtimezone.html#offsetFromUtc. So what does not work or is not in the documentation?

                  M Offline
                  M Offline
                  Mikeeeeee
                  wrote on last edited by Mikeeeeee
                  #8

                  @JonB thank!
                  The language for the output of time zone names depends on the language of the operating system?

                  it is code works:

                      listTimeZome = QTimeZone::availableTimeZoneIds();
                      for(int i = 0; i < listTimeZome.size(); i++)
                      {
                          QTimeZone timeZone(listTimeZome[i]);
                          QString displayNameTimeZone = timeZone.displayName(QTimeZone::StandardTime);
                          int utc = timeZone.offsetFromUtc(QDateTime::currentDateTime());
                          qDebug()<< "name" << displayNameTimeZone;
                          qDebug()<< "utc" << utc;
                      }
                  
                  JonBJ 1 Reply Last reply
                  0
                  • M Mikeeeeee

                    @JonB thank!
                    The language for the output of time zone names depends on the language of the operating system?

                    it is code works:

                        listTimeZome = QTimeZone::availableTimeZoneIds();
                        for(int i = 0; i < listTimeZome.size(); i++)
                        {
                            QTimeZone timeZone(listTimeZome[i]);
                            QString displayNameTimeZone = timeZone.displayName(QTimeZone::StandardTime);
                            int utc = timeZone.offsetFromUtc(QDateTime::currentDateTime());
                            qDebug()<< "name" << displayNameTimeZone;
                            qDebug()<< "utc" << utc;
                        }
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @Mikeeeeee said in How get list all time zone?:

                    The language for the output of time zone names depends on the language of the operating system?

                    That I do not know. I do not see a method offering to translate these names into locale/language.

                    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