Angular2日期格式化

1、ts中調用
1.引入: import { DatePipe } from '@angular/common';
2.加入構造函數:
constructor(
private http: Http,
private alertService: AlertService,
private datePipe: DatePipe,
) { }
3.方法中調用
 
 let dateStr:string = this.datePipe.transform(data.detailList[i].checkDate,'yyyy-MM-dd');
 
2、html中日期格式化
<div class="cell">
  <div class="title">考覈時間</div>
  <div class="content"> {{chkCheck.checkDate | date: 'yyyy-MM-dd'}}</div>
</div>
相關文章
相關標籤/搜索