问题描述
我正在创建两个mat-datepicker,一个使用"MM/YYYY"格式,另一个使用"DD/MM/YYYY"格式,但是我无法在模块中配置这两种格式.
I'm creating two mat-datepickers, one with the format "MM/YYYY" and another with the format "DD/MM/YYYY",but i can't configure both formats in the module.
我试图将MM/YYYY的设置放在一个模块中,而在应用程序模块中将DD/MM/YYYY的设置放在一个模块中.
I tried to put in one module the settings for MM/YYYY and in the app module the settings for DD/MM/YYYY.
代码1:
export const MY_FORMATS = {
parse: {
dateInput: 'MM/YYYY',
},
display: {
dateInput: 'MM/YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
},
...
providers: [{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS}]
};
代码2:
export const MY_FORMATS = {
parse: {
dateInput: 'DD/MM/YYYY',
},
display: {
dateInput: 'DD/MM/YYYY',
monthYearLabel: 'DD MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'DD MMMM YYYY',
},
};
...
providers: [{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS}]
})
如果我在设置中使用DD/MM/YYYY格式,则所有日期均显示为DD/MM/YYYY,如果我不使用,则所有日期均显示为MM/YYYY.我应该怎么做才能将一个日期显示为MM/YYYY,将另一个日期显示为DD/MM/YYYY?
If i use the DD/MM/YYYY format in the settings,all dates show as DD/MM/YYYY,if i don't use,all dates show as MM/YYYY. What should i do to show one date as MM/YYYY and another as DD/MM/YYYY?
推荐答案
您已经阅读了吗? https://medium.com/@kristinahertmann/带有角材料的多语言日期格式-b8598415d117
在此示例中,可以找到正在工作的 stackblitz .
Working stackblitz for this example can be found HERE.
这篇关于mat-datepicker上的多种dateInput格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!