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>
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'}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With