You can find the official docs here. Output from the console:
The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS".
I used DatePipe
for this, but you could go with formatDate
also (see here for more).
In your component:
import { DatePipe } from '@angular/common';
constructor(
private datePipe: DatePipe
)
ngOnInit() {
this.dateControl.setValue(this.datePipe.transform(this.defaultValues, 'yyyy-MM-ddTHH:mm:ss'));
}
In your module declarations (e.g. app.module.ts) add DatePipe
:
import { DatePipe } from '@angular/common';
@NgModule({
declarations: [
AppComponent,
// ...
],
imports: [
// ...
],
providers: [
DatePipe,
// ...
],
exports: // ...
bootstrap: [AppComponent]
})
export class AppModule { }