角度日期选择器更改日期格式 [英] Angular Datepicker change dateformat
问题描述
我使用来自 Angular Material 的 DatePicker,我想将输出格式更改为 yyyy/mm/dd
.
i use the DatePicker from Angular Material and I would like to change the output format to yyyy/mm/dd
.
目前它以以下格式打印日期:Wed Nov 14 2018 00:00:00 GMT+0100(中欧正常时间)
Currently it prints the date in the following format: Wed Nov 14 2018 00:00:00 GMT+0100 (Central European Normal Time)
我该怎么做?
datepicker = new FormControl('', [Validators.required]);
console.log(this.datepicker.value.toString());
推荐答案
DatePicker
使用日期对象.当您在调试控制台上打印时,您将始终以完整模式看到日期.如果您希望组件以特定格式显示日期,则需要在模块上配置库.
DatePicker
works with date object. When you print on debugging console you will always see the date in full mode.
If you want that your component shows the date in a specific format, you need to configure the library on the module.
@NgModule({
providers: [
{provide: MAT_DATE_LOCALE, useValue: 'en-GB'},
],
})
export class MyApp {}
在官方文档上提供了更多信息.我希望它有所帮助.
More information are available on official documentation. I hope it helps.
这篇关于角度日期选择器更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!