Angular 角度-角度6如何编辑日期格式?
数据从数据库传输到表中。数据库中的数据类型datetimeAngular 角度-角度6如何编辑日期格式?,angular,date,format,Angular,Date,Format,数据从数据库传输到表中。数据库中的数据类型datetime 列属性insertDate如何编辑日期格式?您可以使用Angular的DatePipe以自定义格式编辑日期 附上一份表格供你参考 示例说明: <ng-container *ngFor="let column of columns"> <ng-container *ngIf="column.isModelProperty" [matColumnDef]="column.property">
列属性insertDate如何编辑日期格式?您可以使用Angular的DatePipe以自定义格式编辑日期 附上一份表格供你参考 示例说明:
<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;
}
有关实现日期管道的更多信息,您也可以参考此文件您的意思是在数据库中编辑日期本身吗?或者在template中以自定义格式显示日期?@Vojtech我想在template mat table列InsertDate中以自定义格式显示日期非常感谢。我解决了。构造函数senderv2,datePipe:datePipe{this.insertDate=datePipe.transformsenderv2.insertDate,'dd-MM-yyyy';}如何执行此操作?datePipe.transform返回一个字符串,而不是日期,它应该为您提供赋值error@Dseaster您好,我附上了一个Stackblitz演示,供您参考:
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
}
}