Description

The wpforms_datetime_time_formats filters the time field formats available for the Date Picker in the form builder.

Parameters

$time_formats
(array) (Required) Time format options.

Source

wpforms/includes/functions/data-presets.php

More Information

The filter is applied to an array containing format options for time fields. These options are provided within the form builder when using the Date Picker option.

This filter can be used to add additional format options. The format will determine how the time field selections are displayed to the user, how times appear in entries and notifications, and also how time field selections appear within the database.

By default, WPForms provides two formats for the Time field. a 12 H and a 24 H.

Please see the PHP DateTimeInterface reference for additional format options.

Examples

In our example below, we’re keeping all the default time formats but adding a new one that will appear on the page as 16:04:37 when using the H:i:s format.

/**
 * Filters the time field formats available for the Date Picker in the form builder.
 * 
 * @link   https://wpforms.com/developers/wpforms_datetime_time_formats/
 *
 * @param  array $time_formats Time format options.
 * @return array
 */

function  wpf_dev_date_field_time_formats ( $time_formats ) {

        // Displays 2-digit hour, 2-digit minute, and 2-digit seconds
	$time_formats[ 'H:i:s' ] = 'HH:MM:SS';

	return $time_formats;
}
add_filter( 'wpforms_datetime_time_formats', 'wpf_dev_date_field_time_formats', 10, 1 );


Article Reference: How to Create Additional Formats for the Date Time Field Time Picker