我想将默认日期格式 (YYYY-MM-DD) 更改为其他格式,例如 (MM-DD-YYYY)。
这是我的日历 HTML 结构。
<mat-form-field class="full-width">
<input matInput [matDatepicker]="picker"
[(ngModel)]="currentDay"
(dateChange)="currentDayChanged()"
required
placeholder="date"
name="currentDay">
<mat-datepicker-toggle matSuffix
[for]="picker">
</mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
在 AppModule 中设置您的区域设置!
以巴西为例,
import { LOCALE_ID } from '@angular/core';
import localePt from '@angular/common/locales/pt';
registerLocaleData(localePt, 'pt-BR');
@NgModule({
declarations: [
AppComponent
],
imports: [],
providers: [
{ provide: LOCALE_ID, useValue: 'pt-BR' }
],
bootstrap: [AppComponent]
})
export class AppModule { }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)