Create a custom date format Our organization's style guide expects dates in this format: 


  Oct. 31 2018 01:30 p.m.


I looked the date format drop-down in our views, and there were several options, including a custom one. However, I noticed that none of these are able render the post meridien with abbreviating periods. 

There is option for a custom date format, but it seems to use the encoding for PHP date() function. Looking at the manual, there is a, which gives me pm, and A, which gives me PM, but I don't see anything specifying one with periods. 

I looked in the code base for where date formatters are stored, and they all seem to be yaml files specifying date() formats:

$ cat core/modules/system/config/install/core.date_format.html_yearless_date.yml
...
pattern: m-d
...


So it seems that the built-in custom date formats are limited to what can be specified with PHP's date() function. 

I googled for ways to create a custom date format, but only found explanations of where to specify a custom date format: https://www.ostraining.com/blog/drupal/d8-dates/

How can I create a date formatter where I can use PHP code to give myself a date format with properly abbreviated meridiens?
You are correct, the core date.formatter service uses the native PHP date formatting strings, none of which have 'a.m.' or 'p.m.' in them.

If you really need this, I suspect this would work.


Create a new module, with a class that extends DateFormatter.
In the format method, call the parent method, and then do string replacment to convert 'am' to 'a.m.' and 'pm' to 'p.m.' 
Replace the date.formatter service with the one you created.


This may have side effects that I'm not thinking of right now.