【问题标题】:PrimeNG Calendar - Date displayed incorrectlyPrimeNG 日历 - 日期显示不正确
【发布时间】:2022-01-28 10:57:24
【问题描述】:

我正在使用 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>

【问题讨论】:

    标签: angular primeng primeng-calendar


    【解决方案1】:

    根据PrimeNG Calendar (DateFormat section)

    yy - 年份(四位数)

    因此您应该应用带有“yy”的日期格式,如下所示:

    dateFormat="dd/mm/yy"
    

    Sample Demo on StackBlitz

    【讨论】:

    • 成功了。谢谢。在我看来,用“yy”表示四位数的年份是愚蠢的,但我太肤浅了。
    猜你喜欢
    • 1970-01-01
    • 2014-12-20
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 2015-02-14
    • 2016-06-07
    相关资源
    最近更新 更多