How to display a node's last saved date? Drupal 8 already displays the last saved date in page edit form. I want to add a field to a node that displays it again. I am using hook_form_alter() and doing this in my module, but it displays the current date.

  if ($form_id == 'node_page_edit_form') {
    $form['field_message2'] = array(
      '#type' =&gt; 'item',
      '#title' =&gt; t('Changed date'),
      '#weight' =&gt; -1,
      '#markup' =&gt; format_date(time(), $created),
    );
  }


How do I display the last saved date?
The arguments you are passing a format_date() are wrong: The second argument is the format used for the date, not another timestamp.

You should code similar to the following one.

  if ($form_id == 'node_page_edit_form') {
    $node = $form_state-&gt;getFormObject()-&gt;getEntity();
    $form['field_message2'] = array(
      '#type' =&gt; 'item',
      '#title' =&gt; t('Changed date'),
      '#weight' =&gt; -1,
      '#markup' =&gt; format_date($node-&gt;getChangedTime(), 'medium'),
    );
  }


Even better, you should use the service Drupal provides for formatting dates.

  if ($form_id == 'node_page_edit_form') {
    $node = $form_state-&gt;getFormObject()-&gt;getEntity();
    $form['field_message2'] = array(
      '#type' =&gt; 'item',
      '#title' =&gt; new \Drupal\Core\StringTranslation\TranslatableMarkup('Changed date'),
      '#weight' =&gt; -1,
      '#markup' =&gt; \Drupal::service('date.formatter')-&gt;format($node-&gt;getChangedTime(), 'medium'),
    );
  }


Instead of 'medium', you can use the default value, or another one you prefer.