2 Replies Latest reply on Feb 16, 2016 2:01 PM by gkaiseril

    Time Format in javascripts

    uxk Level 1

      Hello,

      Can we write the following in javascripts:

      1) 17:30 hrs instead of 17.5 for hours(time) -- Does javascripts recognize fractions?

      2) Can we use >= (greater or equal to) or (specify a range) <x< in javascripts.


      <script>

      var today = new Date();

      var hourNow = today.getHours();

      var greeting;

       

      if (hourNow > 17.5) {

      greeting = 'Evening!';

      </script>

        • 1. Re: Time Format in javascripts
          try67 MVP & Adobe Community Professional

          The answer is yes to both questions. However, there is logical mistake in your code because the getHours method returns an integer.

          So if you want to check if it's past 17:30 then you need to look at both the hours and the minutes values of your Date object.

           

          You're also missing a closing curly brackets at the end of your code...

          • 2. Re: Time Format in javascripts
            gkaiseril MVP & Adobe Community Professional

            You might want to review the MDN JavaScript Reference for the getHours() and getMinutes() methods of the date object.

            var today = new Date();
            var hourNow = today.getHours();
            var MinutesNow = today.getMinutes();
            var greeting = "";
            if (hourNow * 60 + MinutesNow) > 17 * 60 + 30) {
            greeting = 'Evening!';
            }

             

            One could also use the Acrobat JavaScirpt's util.printd() method.

             

            var today = new Date();
            var greeting = "";
            if (Number(util.printd("HH.MM", today)) > 17.30) {
            greeting = 'Evening!';
            }