Angular 2 show current formatted date

前端 未结 3 733

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.

    0 讨论(0)
  • 2020-12-19 17:46

    Use Angular2 built in Date Pipe

    {{whatTime | async | date:'yMdjm'}}
    
    0 讨论(0)
  • 2020-12-19 17:49

    You should use this:

    import moment from 'moment';
    

    Then you should call it like that:

    moment(timestamp).fromNow();
    

    This will give you the current time.

    0 讨论(0)
提交回复
热议问题