abcid d abcid d - 29 days ago 6
CSS Question

Angular Breaking Date and Time

I have this code

<ng-template>{{date:'MM/dd/yyyy h:mm:ss a Z'}}</ng-template>
and it will show a long line date and time. I want to make a break in between data and time by enter
<br />
, but it doesn't work.
Any idea?
Thanks!

Answer Source

To solve this you can use these pipes:

{{ dateObj | date }}               // output is 'Jun 15, 2015'
{{ dateObj | date:'medium' }}      // output is 'Jun 15, 2015, 9:43:11 PM'
{{ dateObj | date:'shortTime' }}   // output is '9:43 PM'
{{ dateObj | date:'mmss' }}        // output is '43:11'

This will give you the desired time or date on the correct lines

<ng-template>{{date | date}}<br> {{ date | date:'shortTime' }}</ng-template>

More info can be found at the docs: DatePipe