0

Real time clock within a form view

Hello Again All,

Is it possible to have clock (face or digital) that keeps the current local time within a form view?

Thanks,

Sam

20 replies

null
    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    Hi Sam, something like that, I can send you the code tomorrow the router die today.

      • Sam.1
      • 1 yr ago
      • Reported - view

        yes, thank you Rafael!

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

       Real Time Clock

      • Sam.1
      • 1 yr ago
      • Reported - view

       thanks !!
      I’ll let you know how it works

      • Sam.1
      • 1 yr ago
      • Reported - view

       The time does not show the real time after one minute. I need to leave the form and return to see the current time.

      Also, how do I change the time zone(move up one hour)

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      sam 

      hi Sam On one of these lines. I place de Madrid on the díaLightSavingTimeZone2(0)) change de 2 o 1 if summer or winter time.

      The best I find in the Forum.

       

      let katmandú := " Katmandú" + "<br>" + SunsetAndRise(27.7, 85.3, 5.75);
      let ulaanbaatar := "" + " Ulaanbaatar " + "<br>" + SunsetAndRise(47.9, 106.9, 8);
      let tongatapu := " Tongatapu" + "<br>" + SunsetAndRise(-21.2, -175.3, 13);
      let newYork := "Nueva York" + "<br>" + SunsetAndRise(40.6, -74, dayLightSavingTimeZone2(-5));
      let tokio := " Tokio" + "<br>" + SunsetAndRise(35.65, 139.65, 9);
      let johannesburgo := " Johannesburgo" + "<br>" + SunsetAndRise(26.2, 28, 2);
      let greenwich := "" + " Greenwich " + "<br>" + SunsetAndRise(51.5, 0, dayLightSavingTimeZone1(0));
      let greenwich := "" + " Madrid " + "<br>" + SunsetAndRise(51.5, 0, dayLightSavingTimeZone2(0)) ;

    • red_kite
    • 1 yr ago
    • Reported - view

    a realtime clock like this:

    let css := "
    <style>
    main {
        font: 1.5em 'Courier New',monospace;
    }
    </style>";
    let content := "
    <main id='clock'></main>
    <script>
    function addZero(i) {
              if (i < 10) {i = '0' + i}
              return i;
            };
    setInterval(
        function() {
            let now = new Date();
            let houres = now.getHours();
            let minutes = now.getMinutes();
            let seconds = now.getSeconds();
            let node = document.querySelector('#clock');
            node.innerHTML = addZero(houres) + ':' + addZero(minutes) + ':' + addZero(seconds);
                    }
        , 1000)();
    </script>
    ";
    html(css + content)
    
      • Sam.1
      • 1 yr ago
      • Reported - view

       YES! Thank you—it works!

      Do you have any suggestions how it could be modified to display as 12 hour (AM-PM)?

      • red_kite
      • 1 yr ago
      • Reported - view

       a little bit shorter

      let css := "
      <style>
      main {
          font: 1.5em 'Courier New',monospace;
      }
      </style>";
      let content := "
      <main id='clock'></main>
      <script>
      setInterval(
          function() {
              let now = new Date();
              let node = document.querySelector('#clock');
              node.innerHTML = now.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', second:'numeric', hour12: true });
                      }
          , 1000)();
      </script>
      ";
      html(css + content)
      
      • Sam.1
      • 1 yr ago
      • Reported - view

       thanks again for streamlining the code!

      is there a way to change it from a 24 hour clock to 12 hours—A.M.—P.M.?

      • red_kite
      • 1 yr ago
      • Reported - view

       what do you mean with "change"? You can change the display with: hour12: true or false.

      • Sam.1
      • 1 yr ago
      • Reported - view

       true. I would like to display with A.M. and P.M.

      in the morning an example would be like 9:22 A.M. = this with the code is 09:22

      in the evening, an example would be 10:25 P.M.— this is the same as 22:25 with the current code

      • red_kite
      • 1 yr ago
      • Reported - view

      like this?

      • Sam.1
      • 1 yr ago
      • Reported - view

      MZyes—PERFECT!!

      thanks again Rafael!

      sam

      • Sam.1
      • 1 yr ago
      • Reported - view

       Rafael, when I enter the full screen mode the time disappears.

      Do you have any idea why that would happen?

      sam

      • red_kite
      • 1 yr ago
      • Reported - view

       I don't know. I think, Javascript is more of a hack for Ninox and doesn't always work safely. Sometimes it works, sometimes it doesn't. The watch is just for fun for me. I'm sorry if I couldn't help you. M

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

       Hi Sam 

      On Full Screen I don't have problem

      • Alan_Cooke
      • 1 yr ago
      • Reported - view

       This is great I asked CHATGPT to tweak it for a different font and AM/PM.  Here is the revised code.  Make sure you refresh your browser.

      let css := "
      <style>
      main {
          font-family: 'Noto Sans', sans-serif;
          font-size: 1.5em;
      }
      </style>";
      let content := "
      <main id='clock'></main>
      <script>
      function addZero(i) {
          if (i < 10) {i = '0' + i}
          return i;
      }

      setInterval(function() {
          let now = new Date();
          let hours = now.getHours();
          let minutes = now.getMinutes();
          let seconds = now.getSeconds();
          let meridiem = hours >= 12 ? 'PM' : 'AM'; // Determine AM or PM

          // Convert hours to 12-hour format
          hours = hours % 12 || 12;

          let node = document.querySelector('#clock');
          node.innerHTML = addZero(hours) + ':' + addZero(minutes) + ':' + addZero(seconds) + ' ' + meridiem;
      }, 1000);
      </script>
      ";
      html(css + content)

      • Sam.1
      • 1 yr ago
      • Reported - view

       thanks for the info! 
       

      • Sam.1
      • 1 yr ago
      • Reported - view

       Hi Alan, thank you for the contribution! With this code when I expand to full screen the field is still present but the time is absent.

      Do you have any suggests to why?

      Sam

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 20Replies
  • 206Views
  • 4 Following