PDF Editing Issues

Convert 24-Hour Time to AM/PM in an Acrobat Form Field

Rana GarciaRana Garcia Nov 19, 2026 868 views

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.

Convert 24-Hour Time to AM/PM in an Acrobat Form Field
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

Open the PDF in Acrobat and select Prepare a form from the tools menu.

2
Open field properties

Double-click the text field for the time, or right-click it and select Properties.

3
Select a custom format

In the field properties, open the Format tab, choose Custom, and click Edit next to Custom Format Script.

4
Enter the 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; }

5
Test the field

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.

Add a custom time format script to the Acrobat field
Display and validation: This script formats the display but does not reject invalid entries or permanently convert the underlying field value. For multiple fields, consider defining a document-level function and calling it from each field's custom format script.
Free Microsoft Office alternative

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.

Open and work with PDF documents alongside other filesCompatible with Microsoft Office formats such as DOCX, XLSX, and PPTXUse a familiar interface for an easier transition from Microsoft OfficeAccess document, spreadsheet, presentation, and PDF tools in one suite
microsoft office alternative - wps office

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.