Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Timestamp - Welches Format für DP?

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Timestamp - Welches Format für DP?

    This topic has been deleted. Only users with topic management privileges can see it.
    • paul53
      paul53 @warhammer73 last edited by paul53

      @warhammer73 sagte: Warnung in der setState Zeile.

      new Date() erzeugt ein Objekt - keinen String.

      mickym 1 Reply Last reply Reply Quote 0
      • mickym
        mickym Most Active @paul53 last edited by

        @paul53 sagte in Timestamp - Welches Format für DP?:

        @warhammer73 sagte: Warnung in der setState Zeile.

        new Date() erzeugt ein Objekt - keinen String. Ich weiß nicht, ob man ein Date-Objekt in einen Datenpunkt schreiben kann.

        Na dann schreibt man ggf. mit new Date().getTime() . geht das nicht?

        paul53 1 Reply Last reply Reply Quote 0
        • paul53
          paul53 @mickym last edited by

          @mickym sagte: new Date().getTime() . geht das nicht?

          Ja, das ist dann aber eine große Zahl (ms).

          mickym 1 Reply Last reply Reply Quote 0
          • mickym
            mickym Most Active @paul53 last edited by

            @paul53 Aber die Timestamps sind doch in ms abgespeichert?

            paul53 1 Reply Last reply Reply Quote 0
            • paul53
              paul53 @mickym last edited by

              @mickym sagte: Timestamps sind doch in ms abgespeichert?

              Ja, die Timestamps der Datenpunkte.

              1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @warhammer73 last edited by paul53

                @warhammer73 sagte: in den DP wird aber 16:06 geschrieben.

                In den Datenpunkt wird die UTC-Zeit geschrieben. Erzeuge einen String mit der lokalen Zeit mittels

                new Date().toLocaleString()
                

                Ergebnis: "5.2.2023, 17:28:50"

                W haus-automatisierung 2 Replies Last reply Reply Quote 0
                • W
                  warhammer73 @paul53 last edited by

                  @paul53 Danke!

                  ... gibts auch noch einen Weg das mir die Protokollausgabe gleich verrät was ihr nicht gefällt?

                  paul53 1 Reply Last reply Reply Quote 0
                  • paul53
                    paul53 @warhammer73 last edited by paul53

                    @warhammer73 sagte: Protokollausgabe gleich verrät was ihr nicht gefällt?

                    Im Tab "Protokolle" steht, wenn der Datenpunkttyp nicht zum Typ des geschriebenen Wertes passt.

                    1 Reply Last reply Reply Quote 0
                    • haus-automatisierung
                      haus-automatisierung Developer Most Active @warhammer73 last edited by haus-automatisierung

                      @warhammer73 Laut Doku sollte role: date entweder

                      date (common.type = string - parsable by "new Date(ddd)" string

                      oder

                      date (common.type = number - epoch seconds * 1000

                      sein. Also z.B. geht auch

                      createState(`${folderName}.${room}.Lastchange`, Date.now(), { name: 'Last change', type: 'number', role: 'date' });
                      

                      Gespeichert wird dann ein Timestamp, aber dank der Rolle zeigt z.B. der Admin-Adapter das in einem lesbaren Format an. Das ist meine bevorzugte Variante, weil man damit am besten weiter arbeiten kann (falls nötig).

                      1 Reply Last reply Reply Quote 0
                      • haus-automatisierung
                        haus-automatisierung Developer Most Active @paul53 last edited by

                        @paul53 sagte in Timestamp - Welches Format für DP?:

                        In den Datenpunkt wird die UTC-Zeit geschrieben. Erzeuge einen String mit der lokalen Zeit mittels
                        new Date().toLocaleString()

                        Dann aber bitte nicht role: date setze, weil dann versucht z.B. der Admin das zu parsen / gibt den Inhalt an new Date(). Und bei einem Deutschen Datumsformat geht das oft schief. Sonst lieber als UTC-String oder halt als Timestamp (s.o.).

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        823
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        4
                        11
                        278
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo