在角度日期选择器中重置当前日期选择

时间:2020-08-01 07:23:48

标签: angular

我的日期选择器正在按照UTC日期运行。因此,当我在12:01AM打开日期选择器时,默认选择(在当前日期)仍在前一个日期,如下图所示。 在这里,我将系统时间设置为Aug 2 12:10AM。但是选择仍然位于Aug 1st本身。

<mat-form-field appearance="fill">
                          <mat-label
                            >Date Of Birth
                            <span style="color: red;">*</span></mat-label
                          >
                          <input
                          readonly
                            [max]="today"
                            formControlName="dateOfBirth"
                            matInput
                            [matDatepicker]="pickerxx"
                            (click)="pickerxx.open()"
                            
                          />
                          <mat-datepicker-toggle
                            matSuffix
                            [for]="pickerxx"
                          ></mat-datepicker-toggle>
                          <mat-datepicker #pickerxx></mat-datepicker>
                          <mat-error
                            *ngIf="dateOfBirth.invalid && dateOfBirth.errors.required">
                            {{ alertMessage.dobReq }}
                          </mat-error>                              
</mat-form-field>

这是我的ts代码:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder, FormArray } from '@angular/forms';
import { Router } from '@angular/router';

public addPeopleForm: FormGroup;
public today = new Date();

constructor(
    private formBuilder: FormBuilder,
    private router: Router,    
    private tService: TimezoneConversionService
) {}

get dateOfBirth() { return this.addPeopleForm.get('dateOfBirth'); }

ngOnInit(): void {
    this.today = this.tService.convertToLocalTimeZone(new Date());  
    this.initAddUser(); 
}

initAddUser() {
    this.addPeopleForm = this.formBuilder.group({    
      'dateOfBirth': new FormControl('', [Validators.required]),               
    });       
}

如何使它在默认时区工作?

enter image description here

0 个答案:

没有答案