I need to set time for angular material datepicker, as if i select current date it gives me the current time of the system. I want to set the time as 00:00:00. How can i do that?
I am using reactive forms. here is the code.
today = new Date();
createForm() {
this.newForm = this.fb.group({
date: this.today
})
}
html
<div class="input-group">
<span class="input-group-addon" (click)="dt.open();">
<input [matDatepicker]="dt" type="text" class="input-form input_fullWidth"formControlName="date" fullWidth fieldSize="small">
<div class="datepicker-icon-div">
<i class="fa fa-calendar"></i>
</div>
</span>
<span>
<mat-datepicker #dt></mat-datepicker>
</span>
</div>
here is the output i am getting
Tue Mar 31 2020 11:33:47 GMT+0530 (India Standard Time)
I want the time should be
Tue Mar 31 2020 00:00:00 GMT+0530 (India Standard Time)
you can add below way it working
getDate : any
createForm() {
this.newForm = this.fb.group({
date: this.getDate;
});
ngOnInit(){
const today = new Date();
const SelectedDate = `${today.getFullYear()}-${today.getMonth() + 1}-${today .getDate()}`;
this.getDate = new Date(SelectedDate);
this.createForm();
}