角日期选择器在IE中显示错误的年份(而不是2019年显示的1919年) [英] Angular date picker showing wrong year in IE(instead of 2019 its showing 1919)

查看:47
本文介绍了角日期选择器在IE中显示错误的年份(而不是2019年显示的1919年)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么IE从角度日期选择器显示错误的日期(年).在chrome中,它可以正常工作,但在IE中则不能.如果我得到日期1/1/2019,它将显示1/1/1919,类似于1/1/2016-> 1/1/1916.基本上它显示了100年前.在chrome中,一切都很好(显示1/1/2019-> 1/1/2019)

I dont know why IE is showing wrong date(year) from angular date picker. In chrome it works fine but not in IE. If I get date 1/1/2019 it shows 1/1/1919, similarly for 1/1/2016-->1/1/1916. Basically it shows 100 years back. In chrome everything is fine(It shows 1/1/2019-->1/1/2019)

此处是已设置的值

 if (releaseEntryTypeId === 1) {
                this.releaseModificationItem.releaseManagementInteractiveForm
                .get('startDate')
                .setValue(moment.utc(this.releaseDetails.startDate).toISOString());
              }

formBiuilder

formBiuilder

 this.releaseManagementInteractiveForm = this.formBuilder.group({
      releaseEntryType: new FormControl(null, [Validators.required]),
      ..............................................
      startDate: new FormControl(moment())
    });

HTML

<div class="schedule-release-date" *ngIf="formControls['releaseEntryType'].value === 1">
      <mat-form-field [floatLabel]="">
        <input required matInput [matDatepicker]="releaseDatePicker" placeholder="Release Date" [formControl]="formControls['startDate']">
        <mat-datepicker-toggle matSuffix [for]="releaseDatePicker"></mat-datepicker-toggle>
        <mat-datepicker #releaseDatePicker></mat-datepicker>
      </mat-form-field>
    </div>

我在stackoverflow上发现了类似的问题:-

I found similar issue by someone on stackoverflow:- How do I fix a year of two digits in mat-datepicker in IE browser?

按照解决方案,我尝试实现一下功能,但是它对我也不起作用

As per solution, I tried to implement moment but it didn't work for me too

推荐答案

您可以参考

You could refer to this online demo to make angular datepicker work in IE 11.

您可以下载项目,CD进入项目并运行 npm install 来安装项目.我还在本地修改了 datepicker-moment-example.ts 文件,如下所示:

You could download the project, cd into the project and run npm install to install the project. I also modified the datepicker-moment-example.ts file like this in local:

...
import * as _moment from 'moment';
// tslint:disable-next-line:no-duplicate-imports
//import {default as _rollupMoment} from 'moment';

const moment = _moment;
...

该演示与您发现的类似问题的答案基本相同.您需要运行 npm i moment 来安装软件包并实施时刻.

The demo is mostly the same with the answer in the similar issue you found. You need to run npm i moment to install the package and implement moment.

这篇关于角日期选择器在IE中显示错误的年份(而不是2019年显示的1919年)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆