I want to show my time as AM and PM, is it possible with angular date filter. I have tried the below code but doesn't work for me.
<div>{{ '12:31:07' | date:'HH:mm' }}</div>
I want to show my time as AM and PM, is it possible with angular date filter. I have tried the below code but doesn't work for me.
<div>{{ '12:31:07' | date:'HH:mm' }}</div>
According to Angular documentation for date filter, the date argument should be in a valid format.
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
So, you need to format your time string beforehand. For example;
<div>{{ '2017-09-04T12:31:07' | date:'h:mma' }}</div>
will give you the required result.
Try a custom filter:
HTML:
JS:
Demo: http://jsfiddle.net/U3pVM/33868/
Or use default filters:
try:
or
You can also try
'medium'
or'short'
for date filterRefer: https://docs.angularjs.org/api/ng/filter/date