Wrong year for 1st January 2022

Viewed 984

I'm using Angular's own date pipe to format dates. However I've discovered an error when it comes to a specific date: 1st January 2022.

If you visit = https://stackblitz.com/edit/angular-ivy-qrnysm?file=src%2Fapp%2Fapp.component.ts

You'll see I have 2 dates: 2022-01-01 and 2022-01-02. In the template they are both using | date:'dd/MM/YYYY':'GMT'. But the first date formats to = 01/01/2021 (wrong year) but the second date formats to 02/01/2022 (correct year).

Has anyone else experienced this?

2 Answers

The “yyyy” represents the calendar year of the date while the “YYYY” represents the year of the week.. Your format need to be written as small case for years

  This is date 1: {{formattedIssueDate1 | date:'dd/MM/yyyy':'GMT'}}

I think the format should be date:'dd/MM/yyyy':'GMT'

Related