简体   繁体   中英

Date displayed incorrectly by primeng calendar

I'm working with Angular and PrimeNG and I'm facing this problem: there is a form and a specific field is obtained with a calendar. When I pick the date, the format is incorrect, because the year is duplicated: ie 25/01/20222022 rather than 25/01/2022 Here there is the ts file:

 setDate(event, formControlName) {
    this.formGroup.controls[formControlName].patchValue(event);
  }

while the HTML file is

 <p-calendar id="tempoAdeguamento" aria-describedby="tempoAdeguamentoHelp"
                    formControlName="tempoAdeguamento" [readonly]="isReadyOnlyForm()" [showIcon]="true"
                    class="esiti col-md-12 pl0 pr0" dateFormat="dd/mm/yyyy" [minDate]="minDate" [monthNavigator]="true"
                    [yearNavigator]="true" [yearRange]="yearRange" (onSelect)="setDate($event,'tempoAdeguamento')">
                  </p-calendar>

According to PrimeNG Calendar (DateFormat section) ,

yy - year (four digit)

Hence you should apply the date format with 'yy' as below:

dateFormat="dd/mm/yy"

Sample Demo on StackBlitz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM