Angular 2 show current formatted date

前端 未结 3 732

I have the following code to show the current date:

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

And in my te

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 17:38

    Use Angular's built-in DatePipe:

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

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

    You can read more about Angular's DatePipe and its formats here and you can read more about Angular's pipes in general here.

提交回复
热议问题