Angular 6如何编辑日期格式


<ng-container *ngFor="let column of columns">
<ng-container *ngIf="column.isModelProperty" [matColumnDef]="column.property">
<mat-header-cell *matHeaderCellDef mat-sort-header> {{ column.name }}</mat-header-cell>
<mat-cell *matCellDef="let row">
<span class="fury-mobile-label">{{ column.name }}</span>
{{ row[column.property] }}
</mat-cell>
</ng-container>
</ng-container>
export class Senderv2 {
serviceCode: string;
insertDate : DatePipe;
constructor(senderv2) {
this.serviceCode = senderv2.serviceCode;
this.insertDate = senderv2.insertDate;
}
}
export class ListColumn {
name?: string;
property?: string;
visible?: boolean;
isModelProperty?: boolean;
displayFn: any;
}

数据来自数据库到表。数据库中的数据类型datetime列属性insertDate如何编辑日期格式?

您可以使用Angular的DatePipe以自定义格式编辑日期。

已附上Stacklitz演示供您参考

示例插图:

import { DatePipe } from '@angular/common';

class Sender {
currentDate: any = new Date();    
constructor(private datePipe: DatePipe) {}   // Be sure to import this as a provider either inside Component or on your Module
transformDate() {
this.currentDate = this.datePipe.transform(this.currentDate, 'yyyy-MM-dd');  // 2018-11-23
}
}

有关实现DatePipe的更多信息,也可以参考此答案

最新更新