Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] timestamp eines DP als String ausgeben

    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

    [gelöst] timestamp eines DP als String ausgeben

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

      @martinp
      Wie hast du in Blockly toLocaleString() bekommen?

      Versuche es so:

      Blockly_temp.JPG

      In Javascript muss der Zeitstempel erst in ein Date-Object gewandelt werden.

      new Date(obj.state.ts).toLocaleString('de-DE')
      
      MartinP 1 Reply Last reply Reply Quote 1
      • MartinP
        MartinP @MartinP last edited by MartinP

        @martinp eine Abhilfe, die ausreicht, wenn die Verzögerung, bis Javascript feuert nicht stört habe ich schon selbst gefunden:

        on({ id: [].concat(['0_userdata.0.Puls-Test']), change: 'ne' }, async (obj) => {
          const d = new Date();
          // console.info(([' Timestamp ',(obj.state ? obj.state.ts.toLocaleString() : '')].join('')));
          console.info(([' Timestamp ', d.toLocaleString("DE-de")].join('')));
        });
        
        paul53 1 Reply Last reply Reply Quote 0
        • MartinP
          MartinP @paul53 last edited by

          @paul53 sagte in timestamp eines DP als String ausgeben:

          @martinp
          Wie hast du in Blockly toLocaleString() bekommen?

          Habe ein Test-Blockly aus Versehen unumkehrbar nach Javascript umgewandelt, und brin dann bei Tests in Javascript geblieben...

          Leider scheint der Timestamp des Objekts nicht der aktuellen Zeit zu entsprechen....

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

            @martinp sagte: wenn die Verzögerung, bis Javascript feuert nicht stört

            Für die Auswertung des Zeitstempels ändere Zeile 2:

              const d = new Date(obj.state.ts);
            
            1 Reply Last reply Reply Quote 1
            • MartinP
              MartinP @MartinP last edited by

              Jetzt bin ich völlig verwirrt...

              on({ id: [].concat(['0_userdata.0.Puls-Test']), change: 'ne' }, async (obj) => {
                const d = new Date();
                // console.info(([' Timestamp ',(obj.state ? obj.state.ts.toLocaleString() : '')].join('')));
                console.info([' d.toLocale... ', d.toLocaleString("DE-de")].join(''));
                console.info([' d raw ', d.valueOf()].join(''));
                console.info([' obj to loc ', obj.state.ts.toLocaleString("DE-de")].join(''));
                console.info([' obj raw ', obj.state.ts.toFixed()].join(''));
              });
              

              Ausgabe bei Triggerung:

              javascript.0	20:36:52.375	info	script.js.Spielwiese.TestJs: d.toLocale... 13.3.2025, 20:36:52
              javascript.0	20:36:52.375	info	script.js.Spielwiese.TestJs: d raw 1741894612375
              javascript.0	20:36:52.377	info	script.js.Spielwiese.TestJs: obj to loc 1.741.894.612.371
              javascript.0	20:36:52.378	info	script.js.Spielwiese.TestJs: obj raw 1741894612371
              
              
              paul53 1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @MartinP last edited by

                @martinp sagte: Jetzt bin ich völlig verwirrt...

                @paul53 sagte in timestamp eines DP als String ausgeben:

                In Javascript muss der Zeitstempel erst in ein Date-Object gewandelt werden.

                MartinP 1 Reply Last reply Reply Quote 2
                • MartinP
                  MartinP @paul53 last edited by MartinP

                  @paul53 Okay

                  Danke-Das funzt jetzt

                  on({ id: [].concat(['0_userdata.0.Puls-Test']), change: 'ne' }, async (obj) => {
                    const d = new Date();
                    // console.info(([' Timestamp ',(obj.state ? obj.state.ts.toLocaleString() : '')].join('')));
                    console.info([' d.toLocale... ', d.toLocaleString("DE-de")].join(''));
                    console.info([' d raw ', d.valueOf()].join(''));
                    
                    const e = new Date(obj.state.ts);
                    console.info([' obj to loc ', e.toLocaleString("DE-de")].join(''));
                  });
                  

                  Logging

                  javascript.0	20:49:24.830	info	script.js.Spielwiese.TestJs: d.toLocale... 13.3.2025, 20:49:24
                  javascript.0	20:49:24.830	info	script.js.Spielwiese.TestJs: d raw 1741895364830
                  javascript.0	20:49:24.830	info	script.js.Spielwiese.TestJs: obj to loc 13.3.2025, 20:49:24
                  
                  MartinP 1 Reply Last reply Reply Quote 0
                  • MartinP
                    MartinP @MartinP last edited by MartinP

                    Ich habe den automatisch generierten Code aus Blockly noch ein wenig aufgeräumt...

                    on({ id: [].concat(['mqtt.0.thermostat.logmsg']), change: 'ne' }, async (obj) => {
                      if (!obj.state) return;
                      const e = new Date(obj.state.ts);
                      console.info(([ obj.state.val,' ',e.toLocaleString()].join('')));
                    });
                    

                    Ist nur der erste Schritt - im Logging des iobroker ist der Timestamp ja eigentlich doppelt.

                    Ich will aber einen Vis View machen der mir die letzten X Ausfälle der DS18B20 Fühler auf dem Smartphone zeigt ...

                    Wahrscheinlich muss man da aber schon selber basteln.
                    Bei Vis wird es kein Ausgabefenster-Widget geben, das den Inhalt eines Datenpunktes als Zeilen-Eingabe für das Ausgabefenster interpretiert..

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

                      @martinp sagte: ein wenig aufgeräumt...

                      Die Zeile 2 ist unnötig, da ein DP ohne state nicht triggern kann.

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

                        @paul53 sagte in [gelöst] timestamp eines DP als String ausgeben:

                        @martinp sagte: ein wenig aufgeräumt...

                        Die Zeile 2 ist unnötig, da ein DP ohne state nicht triggern kann.
                        Ist Einleuchtend.

                        Dann machst Du besseren Code, als Blockly. Dort wird im umgewandelten Code sogar zweimal über den ternary Operator ?: die Abfrage gemacht...

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        813
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        2
                        11
                        253
                        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