Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Zeitdifferenz aus Variabel berechnen

    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

    Zeitdifferenz aus Variabel berechnen

    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Diamand2k22 last edited by

      Hallo zusammen,

      ich habe ein Skript, in dem die Zeitdifferenz aktuelle Zeit bis Sonnenaufgang berechnet wird.

      dazu habe ich folgenden Code:

      if ((new Date().getTime()) < getDateObject(getAstroDate('sunrise', undefined, 0)).getTime()) {
                 hrstorun = Math.round(((getAstroDate('sunrise', undefined, 0).valueOf() - (new Date().getTime())) / 3600000) * 10) / 10;
              } else {
                 hrstorun = Math.round(((getAstroDate('sunrise', undefined, 1440).valueOf() - (new Date().getTime())) / 3600000) * 10) / 10;
              }
      

      Jetzt würde ich aber gerne die Differenz nicht aus dem Wert von getAstroDate('sunrise')berechnen, sondern die zeit von einer Variabel nehmen, z.B.
      _sunrise im Format SS:MM und dann die Differenz berechnen.

      wie kann ich das am Besten umsetzen?

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

        @diamand2k22 sagte: Format SS:MM und dann die Differenz berechnen.

        const clock = getState(id).val.split(':');
        const today = new Date();
        today.setHours(clock[0], clock[1], 0);
        let diff = Math.round((new Date(today).getTime() - Date.now()) / 360000) / 10;
        if(diff < 0) diff += 24;
        
        D 1 Reply Last reply Reply Quote 0
        • D
          Diamand2k22 @paul53 last edited by

          @paul53

          hat funktioniert, danke dir!!!

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

          Support us

          ioBroker
          Community Adapters
          Donate

          390
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

          2
          3
          176
          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