Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Timezone ändern

Timezone ändern

Scheduled Pinned Locked Moved Unsolved German
9 Posts 5 Posters 454 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.
  • S Offline
    S Offline
    StefKe
    wrote on last edited by
    #1

    Hallo, wie kann man QDateTime() eine andere Zeitzone zuweisen?

    UTC = QDateTime.fromString("2025-10-26 02:00:00" ,"yyyy-MM-dd hh:mm:ss")
    local = QDateTime(UTC.toLocalTime())
    UTC = UTC.setTimeZone('Australia/Melbourne')
    print('Timezone: ', UTC.timeZone())
    print("UTC time is:", UTC)
    print("Local time is:", local)
    

    Bei 'setTimeZone' wird gemeckert... Wie muss die Zeile richtig lauten?

    Danke - Stefan

    jsulmJ JonBJ 2 Replies Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      SetTimeZone möchte einen string, keinen character.

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

      jsulmJ 1 Reply Last reply
      1
      • S StefKe

        Hallo, wie kann man QDateTime() eine andere Zeitzone zuweisen?

        UTC = QDateTime.fromString("2025-10-26 02:00:00" ,"yyyy-MM-dd hh:mm:ss")
        local = QDateTime(UTC.toLocalTime())
        UTC = UTC.setTimeZone('Australia/Melbourne')
        print('Timezone: ', UTC.timeZone())
        print("UTC time is:", UTC)
        print("Local time is:", local)
        

        Bei 'setTimeZone' wird gemeckert... Wie muss die Zeile richtig lauten?

        Danke - Stefan

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @StefKe said in Timezone ändern:

        Bei 'setTimeZone' wird gemeckert.

        Was heist das denn genau? Bitte immer die Fehlermeldung posten.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          SetTimeZone möchte einen string, keinen character.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Christian-Ehrlicher Das ist wohl Python in diesem Fall

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            StefKe
            wrote on last edited by
            #5

            Hier die Fehlermeldung:

            Ausnahme: TypeError
            'PySide6.QtCore.QDateTime.setTimeZone' called with wrong argument types:
              PySide6.QtCore.QDateTime.setTimeZone(str)
            Supported signatures:
              PySide6.QtCore.QDateTime.setTimeZone(Union[PySide6.QtCore.QTimeZone, PySide6.QtCore.QTimeZone.Initialization], PySide6.QtCore.QDateTime.TransitionResolution = Instance(PySide6.QtCore.QDateTime.TransitionResolution.LegacyBehavior))
              File "C:\Users\Stefan\Documents\Qt\diagramm\test.py", line 7, in <module>
                UTC = UTC.setTimeZone("Australia/Melbourne")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            

            Danke - Stefan

            Pl45m4P 1 Reply Last reply
            0
            • S StefKe

              Hier die Fehlermeldung:

              Ausnahme: TypeError
              'PySide6.QtCore.QDateTime.setTimeZone' called with wrong argument types:
                PySide6.QtCore.QDateTime.setTimeZone(str)
              Supported signatures:
                PySide6.QtCore.QDateTime.setTimeZone(Union[PySide6.QtCore.QTimeZone, PySide6.QtCore.QTimeZone.Initialization], PySide6.QtCore.QDateTime.TransitionResolution = Instance(PySide6.QtCore.QDateTime.TransitionResolution.LegacyBehavior))
                File "C:\Users\Stefan\Documents\Qt\diagramm\test.py", line 7, in <module>
                  UTC = UTC.setTimeZone("Australia/Melbourne")
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              

              Danke - Stefan

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @StefKe

              Versuch mal den String vorher noch zu einem QTimeZone zu machen. Anscheinend mag setTimeZone auch nicht mal direkt einen String sondern akzeptiert nur die in der Meldung beschriebenen Typen.

              UTC = UTC.setTimeZone(QTimeZone("Australia/Melbourne"))
              
              • https://doc.qt.io/qtforpython-6/PySide6/QtCore/QDateTime.html#PySide6.QtCore.QDateTime.setTimeZone
              • https://doc.qt.io/qtforpython-6/PySide6/QtCore/QTimeZone.html

              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              1
              • S Offline
                S Offline
                StefKe
                wrote on last edited by
                #7

                da erscheint die gleiche Fehlermeldung:

                Ausnahme: TypeError
                'PySide6.QtCore.QDateTime.__init__' called with wrong argument types:
                  PySide6.QtCore.QDateTime.__init__(str)
                Supported signatures:
                  PySide6.QtCore.QDateTime.__init__()
                  PySide6.QtCore.QDateTime.__init__(PySide6.QtCore.QDate, PySide6.QtCore.QTime, PySide6.QtCore.Qt.TimeSpec, int = 0)
                  PySide6.QtCore.QDateTime.__init__(PySide6.QtCore.QDate, PySide6.QtCore.QTime, PySide6.QtCore.QDateTime.TransitionResolution = Instance(PySide6.QtCore.QDateTime.TransitionResolution.LegacyBehavior))
                

                Aber vielleicht bin ich es auch falsch angegangen. Hab das Problem jetzt so gelöst:

                    def lbl_max_date_text(self, text):
                        qdate_time = QDateTime.fromString(text, "yyyy-MM-dd hh:mm:ss")
                        if qdate_time.timeZoneAbbreviation() == "Mitteleuropäische Zeit":
                            korr_sec = 3600
                        else:
                            korr_sec = 7200
                

                so kann der gelieferte Date-String in Abhängkeit der Sommer- / Winterzeit in localtime umgerechnet werden. Aber sicherlich hab ich was an anderer Stelle verpasst :-)
                Danke - Stefan

                Pl45m4P 1 Reply Last reply
                0
                • S StefKe

                  da erscheint die gleiche Fehlermeldung:

                  Ausnahme: TypeError
                  'PySide6.QtCore.QDateTime.__init__' called with wrong argument types:
                    PySide6.QtCore.QDateTime.__init__(str)
                  Supported signatures:
                    PySide6.QtCore.QDateTime.__init__()
                    PySide6.QtCore.QDateTime.__init__(PySide6.QtCore.QDate, PySide6.QtCore.QTime, PySide6.QtCore.Qt.TimeSpec, int = 0)
                    PySide6.QtCore.QDateTime.__init__(PySide6.QtCore.QDate, PySide6.QtCore.QTime, PySide6.QtCore.QDateTime.TransitionResolution = Instance(PySide6.QtCore.QDateTime.TransitionResolution.LegacyBehavior))
                  

                  Aber vielleicht bin ich es auch falsch angegangen. Hab das Problem jetzt so gelöst:

                      def lbl_max_date_text(self, text):
                          qdate_time = QDateTime.fromString(text, "yyyy-MM-dd hh:mm:ss")
                          if qdate_time.timeZoneAbbreviation() == "Mitteleuropäische Zeit":
                              korr_sec = 3600
                          else:
                              korr_sec = 7200
                  

                  so kann der gelieferte Date-String in Abhängkeit der Sommer- / Winterzeit in localtime umgerechnet werden. Aber sicherlich hab ich was an anderer Stelle verpasst :-)
                  Danke - Stefan

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by Pl45m4
                  #8

                  @StefKe said in Timezone ändern:

                  da erscheint die gleiche Fehlermeldung:

                  Ist nicht die gleiche Meldung bzw. nicht die selbe Ursache :)

                  Bin jetzt nicht so der Python Experte, aber glaube es failt wegen der erneuten Zuweisung auf UTC...
                  setTimeZone hat, soweit ich sehe, keinen Rückgabe-Typ.
                  (Hab die Zeile vorhin einfach so von dir übernommen)

                  Versuch mal das Beispiel aus der Doku:

                  local = QDateTime(QDateTime.currentDateTime())
                  print("Local time is:", local)
                  UTC = QDateTime(local)
                  UTC.setTimeSpec(Qt.UTC)
                  print("UTC time is:", UTC)
                  print("There are", local.secsTo(UTC), "seconds difference between the datetimes.")
                  
                  • https://doc.qt.io/qtforpython-6/PySide6/QtCore/QDateTime.html#PySide6.QtCore.QDateTime.setTimeSpec

                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  2
                  • S StefKe

                    Hallo, wie kann man QDateTime() eine andere Zeitzone zuweisen?

                    UTC = QDateTime.fromString("2025-10-26 02:00:00" ,"yyyy-MM-dd hh:mm:ss")
                    local = QDateTime(UTC.toLocalTime())
                    UTC = UTC.setTimeZone('Australia/Melbourne')
                    print('Timezone: ', UTC.timeZone())
                    print("UTC time is:", UTC)
                    print("Local time is:", local)
                    

                    Bei 'setTimeZone' wird gemeckert... Wie muss die Zeile richtig lauten?

                    Danke - Stefan

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

                    @StefKe said in Timezone ändern:

                    UTC = UTC.setTimeZone('Australia/Melbourne')

                    setTimeZone(toZone[, resolve=QDateTime.TransitionResolution.LegacyBehavior])

                    Sets the time zone used in this datetime to toZone.

                    setTimeZone() gibt keinen Wert zurück. Also UTC = ist falsch.

                    Und string 'Australia/Melbourne' funktioniert nicht, dass muss byte array sein. Probieren Sie es aus:

                    UTC.setTimeZone(b'Australia/Melbourne')`
                    

                    [Jetzt haben Sie die Antwort von @Pl45m4 . Vieleicht hat er recht.]

                    1 Reply Last reply
                    1

                    • Login

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