Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong year for 1st January 2022

Tags:

angular

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? Here is the code from the stackblitz:

formattedIssueDate1: Date = new Date("2022-01-01T00:00:00Z");
formattedIssueDate2: Date = new Date("2022-01-02T00:00:00Z");

<p>
  This is date 1: {{formattedIssueDate1 | date:'dd/MM/YYYY':'GMT'}}
</p>
<p>
  This is date 2: {{formattedIssueDate2 | date:'dd/MM/YYYY':'GMT'}}
</p>
like image 681
Andrew Junior Howard Avatar asked Dec 02 '25 02:12

Andrew Junior Howard


1 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'}}
like image 51
mr. pc_coder Avatar answered Dec 04 '25 03:12

mr. pc_coder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!