我正在使用 Angular 和 PrimeNG,但遇到了这个问题:有一个表单,并且通过日历获取了特定字段。当我选择日期时,格式不正确,因为年份重复:即 25/01/20222022 而不是 25/01/2022。
TS
setDate(event, formControlName) {
this.formGroup.controls[formControlName].patchValue(event);
}
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>
最佳答案
根据PrimeNG Calendar (DateFormat section) ,
yy - year (four digit)
因此,您应该应用带有“yy”的日期格式,如下所示:
dateFormat="dd/mm/yy"
关于angular - PrimeNG 日历 - 日期显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70850391/