【问题标题】:Angular 8: How can I set time for angular material datepicker?Angular 8:如何设置 Angular 材质日期选择器的时间?
【发布时间】:2020-03-31 06:47:58
【问题描述】:

我需要为角度材料日期选择器设置时间,就好像我选择当前日期它给了我系统的当前时间一样。 我想将时间设置为 00:00:00。 我该怎么做?

我正在使用反应形式。这是代码。

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>

这是我得到的输出

Tue Mar 31 2020 11:33:47 GMT+0530 (India Standard Time)

我想要的时间应该是

Tue Mar 31 2020 00:00:00 GMT+0530 (India Standard Time)

【问题讨论】:

    标签: html angular angular-material angular-material-datetimepicker


    【解决方案1】:

    你可以在下面添加它的工作方式

        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();
       }
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 2016-02-17
      相关资源
      最近更新 更多