Convert 24-Hour Time to AM/PM in an Acrobat Form Field
Question details
Display a four-digit 24-hour time entry in an Acrobat PDF form field as a 12-hour time with AM or PM.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form user enters a time such as 1515 into a text field.
- Observed behavior
- The desired display is 3:15 pm without using a document-level calculation.
Open the PDF in an Acrobat version that can edit form fields, and identify the text field that will receive the time. Check that JavaScript is enabled in Acrobat's JavaScript preferences.
Add a custom time format script to the Acrobat field
Use a field-level format script when one form field needs to display four-digit 24-hour entries as AM/PM times.
A custom format script changes the displayed value rather than requiring a document-level calculation. The script below formats valid four-digit entries from 0000 through 2359 and leaves other entries unchanged.
Open the PDF in Acrobat and select Prepare a form from the tools menu.
Double-click the text field for the time, or right-click it and select Properties.
In the field properties, open the Format tab, choose Custom, and click Edit next to Custom Format Script.
Paste this script into the editor and click OK: var input = String(event.value || ""); var match = /^([01]\d|2[0-3])([0-5]\d)$/.exec(input); if (match) { var hour = parseInt(match[1], 10); var period = hour >= 12 ? "pm" : "am"; var displayHour = hour % 12 || 12; event.value = displayHour + ":" + match[2] + " " + period; }
Close the properties dialog, preview the form, enter 1515 in the field, and move focus to another field. The time should display as 3:15 pm.

Work with PDF forms and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and compatible Office files. It makes it easy to move between document types, though it does not fix Acrobat's custom JavaScript formatting.

Frequently Asked Questions
Where do I add the custom format script in Acrobat?
Open Prepare a form, open the text field's Properties, and select Format > Custom. Click Edit next to Custom Format Script and paste the code there.
Does the script change the stored field value?
No. A custom format script changes how the value is displayed; it does not permanently convert the underlying value.
What happens if someone enters an invalid time?
The sample script leaves entries that do not match a valid four-digit time unchanged. Use a separate validation script if you need to reject invalid entries.
How can I use the same time format in several fields?
Define a document-level JavaScript function and call it from the custom format script of each field. This lets you update the shared formatting logic in one place.
Why might the formatted time not appear in a PDF viewer?
The viewer must support and allow the relevant PDF JavaScript. In Acrobat, check the JavaScript preferences and test the field after moving focus away from it.




