简体   繁体   English

primeng 日历显示日期不正确

[英]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.我正在使用 Angular 和 PrimeNG,我正面临这个问题:有一个表格,并且通过日历获得了一个特定的字段。 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:当我选择日期时,格式不正确,因为年份重复:即 25/01/20222022 而不是 25/01/2022 这里有 ts 文件:

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

while the HTML file is而 HTML 文件是

 <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) ,根据PrimeNG 日历(日期格式部分)

yy - year (four digit) yy - 年(四位数)

Hence you should apply the date format with 'yy' as below:因此,您应该使用 'yy' 应用日期格式,如下所示:

dateFormat="dd/mm/yy"

Sample Demo on StackBlitz StackBlitz 上的示例演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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