I want to change the default date format (YYYY-MM-DD) to some other format like (MM-DD-YYYY).
This is my calendar HTML structure.
<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>
Set in AppModule your locale!
Example for Brazil,
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 { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With