3 Replies Latest reply on Jul 29, 2016 10:43 AM by gkaiseril

    Calculate Military Time 24- Hours

    taylorw32663699

      Hello to all,

       

      This is my first post to the Adobe community. I am here because I am having some trouble with the military time and getting it to go past mid-night. I have my coding set to where the "statrtime" subtracts from the "stoptime" correct but for example, if someone worked from 22:00 till 06:00 it would not calculate correctly.

       

      What I am looking for is the total amount of minutes that have passed from the "stoptime" back until the "starttime".

       

      Below is the current code that I am using:

       

      ((hour2*60)+min2)-((hour1*60)+min1)

       

      Is there any way that I could code this in Adobe Acrobat alone or would I need a third party to help support?

       

      Thanks for any help it would be appreciated greatly!

        • 1. Re: Calculate Military Time 24- Hours
          gkaiseril MVP & Adobe Community Professional

          The valid time range for Military time is 0000 (Midnight) to 2359 (the last minute before Midnight of the next day).  The time format only accepts valid time values for the day. There is no 2500 in any day. If you want to have your time to go past midnight on a day, then you need to add some indicator for the number of days since the start of the event.

           

          If your event spans more than a single day interval, you need to include the date and time strings for the start and end values. Then you convert the start date & time string to the JavaScript date objet and repeat for the end date and time. You can then take the difference in the values to get the elapsed time in milliseconds. You can now convert that value into hours and minutes.

           

          If you are accumulating elapsed times for different events, you will have to write code to format the accumulated hours and minutes.

           

          A sample script:

           

          var nElapsed = "";
          var cStartDate = "27-Jul-2016";
          var cStartTime = "22:00";
          var nElapsed = "";
          var oStartDate = util.scand("dd-mmm-yyyy HH:MM", cStartDate + " " + cStartTime);
          if(oStartDate ==  null) app.alert("Error convertng start time",  1, 0);
          var cEndDate = "28-Jul-2016";
          var cEndTime = "06:00";
          var oEndDate = util.scand("dd-mmm-yyyy HH:MM", cEndDate + " " + cEndTime);
          if(oEndDate ==  null) app.alert("Error convertng end time",  1, 0);

          if(oStartDate != null && oEndDate != null)
          {
          // compute difference in end and start times in minutes;
          var nDiff = Math.floor((oEndDate.getTime() - oStartDate.getTime()) / (1000 * 60));
          // format result in HH:MM;
          var cSign = "";
          if(nDiff < 0) cSigh = "-"
          cElapsed =  cSign + util.printf("%,101.0f:%,102.0f", Math.floor(Math.abs(nDiff) / 60), (Math.abs(nDiff) % 60));
          }
          // event.value = cElapsed;);
          console.show();
          console.clear();
          console.println("Elapsed time: " + cElapsed);

          • 2. Re: Calculate Military Time 24- Hours
            taylorw32663699 Level 1

            OK

            What would the code look like? I set the format  to m/d/yy HH:MM on the form, but how do I convert that to milliseconds?  Do the math and convert the milliseconds back to minutes?  The information is relevant, but not so helpful.  The Acrobat form does not have a clear guide to how they use JAVA.

            Thanks for your input

            • 3. Re: Calculate Military Time 24- Hours
              gkaiseril MVP & Adobe Community Professional

              The "util.scand()" method in Acrobat JavaScript does that conversion for you.