Home > other >  Angular date pipe is displaying the incorrect date
Angular date pipe is displaying the incorrect date

Time:10-19

I got this date 2021-10-08T23:47:34.000Z from the server and anytime i used the angular date pipe on it, it displaying Oct 9, 2021 instead of Oct 8, 2021

<ng-container matColumnDef="created_at">
      <th mat-header-cell *matHeaderCellDef>Date</th>
      <td mat-cell *matCellDef="let element">
        {{ element.created_at | date }}
      </td>
</ng-container>

CodePudding user response:

Angular's DatePipe uses locale to display the date, which means it changes it based on the user's timezone.

You can specify the timezone at the end of the pipe.

{{ element.created_at | date:'mediumDate':'UTC' }}
  • Related