In Drupal 8, there are multiple ways to change the date format of a content type. In this tutorial, I will use the simplest way. For simplicity, I'm going to use Article content type for this tutorial. You can apply the same principle to all other content type. Simply use the machine name of your content type instead of article.
- Copy
./core/modules/node/templates/node.html.twig
into the templates folder of your theme(e.g. For my case, it is./themes/opwtheme/templates/
). - Rename
node.html.twig
tonode--article.html.twig
so that changes will only be applicable to Article content type. - Open
node--article.html.twig
and replace
{% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}`
with
{% set createdDate = node.getCreatedTime|date('F j, Y') %} {% trans %}By {{ author_name }} on {{ createdDate }} {% endtrans %}
Finally, clear all your cache.
Additional variations of date format
date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm date("m.d.y"); // 03.10.01 date("j, n, Y"); // 10, 3, 2001 date("Ymd"); // 20010310 date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01 date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day. date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001 date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month date("H:i:s"); // 17:16:18 date("Y-m-d H:i:s"); // 2001-03-10 17:16:18
Reference
- https://drupal.stackexchange.com/questions/185880/change-article-date-format
- List of date time format that you can use