angular5 时间格式化

在angular1中我们可以在控制器中这样使用filter:

$filter('date')(myDate, 'yyyy-MM-dd HH:mm:ss');

在angular5中则要如下使用:

import { DatePipe } from '@angular/common';
class MyService {
  constructor(private datePipe: DatePipe) {}

  ngOnInit() {
    this.datePipe.transform(new Date(), 'yyyy-MM-dd HH:mm:ss');
  }
}
原文地址:https://www.cnblogs.com/guofan/p/8385949.html