How to Automatically Add 15-Minute Increments to Acrobat PDF Form Time Fields
Question details
The user needs to automatically populate time fields in a PDF form using 15-minute increments based on a previous entry without running into JavaScript text string parsing errors.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where time fields automatically update in 15-minute increments based on user input.
- Observed behavior
- Standard JavaScript Date objects cause parsing problems when created from text strings in Acrobat forms, requiring a more reliable native method to handle time calculations.
Ensure your PDF form fields are correctly named and that you have access to edit JavaScript calculations within your PDF editor's form preparation mode.
Use Acrobat's util.scand Method for Time Calculations
This approach uses Adobe Acrobat's built-in util.scand and util.printd functions to reliably parse, increment, and output time values in form fields.
Standard JavaScript Date objects often fail to parse time strings correctly in PDF forms because they rely on browser-specific or OS-specific locale settings. Acrobat's util.scand method provides a robust way to convert text into date objects by specifying the exact format string, allowing for accurate time manipulation without generic parsing errors.
Open your PDF document in Form Preparation mode. Right-click the time field you want to calculate automatically, and select 'Properties'.
Navigate to the 'Calculate' tab within the Properties dialog box. Select the 'Custom calculation script' option, then click the 'Edit' button.
Write JavaScript to pull the value from the previous time field. For example: var btest = this.getField("StartTime");
Combine a standard date string with the time value to parse it reliably: var d = util.scand("mm-dd-yyyy hh:MM tt", "01-01-1970 " + btest.value);
Use standard JavaScript Date methods on the parsed object to add the required minutes: d.setMinutes(d.getMinutes() + 15);
Format the incremented time back into a string and assign it to the field using util.printd: event.value = util.printd("hh:MM tt", d);

Create and Edit Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to design, edit, and manage interactive PDF forms effortlessly. It is designed to handle common PDF tasks seamlessly while remaining lightweight.
- 1. Open your PDF document: Download and launch WPS Office, then open your PDF document in the WPS PDF Editor.
- 2. Access interactive form tools: Navigate to the 'Form' tab on the top ribbon to access interactive form tools like text fields, checkboxes, and drop-down menus.
- 3. Edit field properties: Double-click any text field to capture time entries and customize its appearance, format, and calculation properties.
- 4. Save and export: Save your customized PDF form to share with users, ensuring high compatibility across different PDF viewers.

Frequently Asked Questions
Why does the standard JavaScript Date object fail in PDF forms?
In PDF environments, parsing text strings directly with standard JavaScript Date constructors can cause unpredictable results or "Invalid Date" errors due to varying localized formats. Using native PDF methods like util.scand ensures consistent parsing by explicitly defining the expected format.
What does util.scand do in Acrobat JavaScript?
util.scand is a built-in Acrobat JavaScript method that converts a formatted text string into a Date object based on a specific format string (like "hh:MM tt"), which safely bypasses common parsing errors associated with standard web JavaScript.
How do I handle empty time fields in my calculation script?
You should add an if-statement at the beginning of your calculation script to check if the source field is empty (e.g., if (btest.valueAsString == "") { event.value = ""; return; }). This prevents the script from throwing an error or defaulting to an incorrect 1970 date.
Can I add 30-minute or 60-minute increments instead?
Yes. Once the time is successfully converted into a Date object using util.scand, you can easily modify the setMinutes() function to add any integer value. For example, use d.setMinutes(d.getMinutes() + 30); to create half-hour intervals.




