【发布时间】:2021-03-25 21:59:10
【问题描述】:
我从 API 收到这样的日期时间:2021-03-21T22:00:00
这是我的组件.ts
ELEMENT_DATA: ReservationList[];
displayedColumns: string[] = ['fullName', 'brand', 'model', 'rentalStartDate', 'rentalEndDate', 'pickUpLocation', 'dropOffLocation', 'totalPrice', 'createdOn'];
dataSource = new MatTableDataSource<ReservationList>(this.ELEMENT_DATA);
//here the data is taken from the API call
public getAll() {
let resp = this.service.reservationList();
resp.subscribe(report => this.dataSource.data= report as ReservationList[])
}
在 HTML 中,日期显示如下:
<ng-container matColumnDef="rentalEndDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> RentalEndDate </th>
<td mat-cell *matCellDef="let element"> {{element.rentalEndDate}} </td>
</ng-container>
并且在表格中日期显示如下 2021-03-21T22:00:00
我想让日期显示不带 T 字符,只显示日期。
【问题讨论】:
-
这是 ISO 8601 日期。
-
我建议你看看像Luxon这样的日期解析库
-
element.rentalEndDate.split("T")[0]在 T 之前给出你的第一部分...
标签: angular typescript date datetime mat-table