简体   繁体   中英

Angular Material Datepicker not keeps local timezone

I have such code:

<mat-form-field class="example-full-width">
                <input
                  [matDatepicker]="picker"
                  formControlName="from"
                  matInput
                />
                <mat-datepicker-toggle [for]="picker" matSuffix></mat-datepicker-toggle>
                <mat-datepicker #picker></mat-datepicker>
</mat-form-field>
<div>{{element.get('from').value.toISOString()}}</div>
<div>{{element.get('from').value}}</div>
this._formBuilder.group({
        from: [moment(source.from).local()]
})

I want that user will work with local timezone, but on server I want to send zero UTC offset.
Initially, it shows the correct date
在此处输入图像描述
But when I choose a different date from datepicker, it clears timezone from date for some reason. I don't need it.
在此处输入图像描述
Why it can be happening?

That was because of moment.tz.setDefault

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM