Using DatePipe in Angular 5.1, I need to format the period field type (AM/PM) in lowercase. According to the documentation,
Tuesday, December 19, 7:00 am
should be
date:'EEEE, MMMM d, h:mm a'
However, the period field type always displays in uppercase, so I see this:
Tuesday, December 19, 7:00 AM
Am I doing something wrong or is this a known defect wtih Angular's date formatting?
You can just split your date to 2 parts:
{{ today | date : 'EEEE, MMMM d, h:mm' }} {{ today | date : 'a' | lowercase }}
...............
UPDATE
Here is another simple way to achieve it, using built in date
pipe and aaaaa matcher (which returns lowercase a
or p
):
<div>{{ today | date : 'EEEE, MMMM d, h:mm aaaaa\'m\'' }}</div>
Updated Stackblitz: https://stackblitz.com/edit/angular-dcpgzb?file=app%2Fapp.component.html
...............
ANGULAR JS solution
app.controller('MainCtrl', function($scope, $locale) {
$locale.DATETIME_FORMATS.AMPMS = ['am', 'pm'];
$scope.today = new Date();
});