Angular 2 shows the current formatted date

I have the following code to display the current date:

this.whatTime = Observable.interval(1000).map(x => new Date()).share();

And in my template:

{{whatTime | async}}

My problem is that the date is too long and not formatted as I wanted.

enter image description here

All that I want to show: 09/15/16 19:07:11

Any ideas?

+4
source share
3 answers

Use Angular inline DatePipe:

{{ whatTime | async | date:'d/M/yy hh:mm:ss' }}

This translates Thu Sep 15 2016 18:15:17 GMT+0200 (Central Europe Daylight Time)into your desired Template 15/9/16 06:15:17.

Read more about Angular DatePipeand its formats here , and you can learn more about Angular pipes in general here .

+5
source

Use Angular2 built-in Date Pipe

{{whatTime | async | date:'yMdjm'}}
+1

:

import moment from 'moment';

:

moment(timestamp).fromNow();

.

0
source

Source: https://habr.com/ru/post/1654723/


All Articles