网站搜索

typescript - 日期的时区在 Date 管道中不起作用 - Angular 5


我正在从数据库的日期列中获取数据。我尝试使用日期管道按时区格式化它。以下是代码

<ng-container matColumnDef="invoiceDate">
          <mat-header-cell *matHeaderCellDef  mat-sort-header> Date </mat-header-cell>
          <mat-cell *matCellDef="let invoice"> {{invoice.invoiceDate | date: 'mediumDate' : 'EDT'}} </mat-cell>
        </ng-container>

它在我的本地环境中运行良好,而应用程序部署在 AWS 上,数据库是 AWS RDS(Postgres),在这个环境中时区不起作用。AWS 机器上的默认时区是 GMT。任何建议都将非常有帮助。例如,数据库中的数据是 2018-08-18 12:00:00,但在前端显示为 2018-08-17 21:00:00

答案#1

我编辑了时区,按照确切的时间增量来解决这个问题。

<ng-container matColumnDef="invoiceDate">
              <mat-header-cell *matHeaderCellDef  mat-sort-header> Date </mat-header-cell>
              <mat-cell *matCellDef="let invoice"> {{invoice.invoiceDate | date: 'mediumDate' : '+0100'}} </mat-cell>
            </ng-container>