Change date format programmatically

I have an entity type with a field called “field_deadline” of type Date, where “Render as a regular field” is set to True. I need to set its format programmatically. I tried the following pieces of code that are ignored:

function hook_date_popup_process_alter(&$element, &$form_state, $context) {
  $element['#date_format'] = 'F j, Y';
}

Also, in a template function as follows:

  $elem = 'field_deadline';
  $lang = $form[$elem]['#language'];
  $form[$elem][$lang][0]['value']['#date_format'] = 'F j, Y';
  $form[$elem]['#date_format'] = 'F j, Y';

Please suggest an approach that works.

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/3/feed