日期垫数据选择器格式错误

发布于 2025-01-10 22:21:18 字数 747 浏览 7 评论 0原文

我想要以 DD/MM/YYYY 格式显示日期。我需要使用带有数据选择器的意大利语和此格式 DD/MM/YYYY。 在我的 app.module 中,我这样做:

export const DD_MM_YYYY_Format = {
  parse: {
      dateInput: 'DD/MM/YYYY',
  },
  display: {
      dateInput: 'DD/MM/YYYY',
      monthYearLabel: 'MMM YYYY',
      dateA11yLabel: 'LL',
      monthYearA11yLabel: 'MMMM YYYY',
  },
};

在我的提供程序中这样做之后:

 { provide: MAT_DATE_LOCALE, useValue: 'it-IT' },
   {provide: MAT_DATE_FORMATS, useValue: DD_MM_YYYY_Format},

所以我在我的组件中这样做,但格式不正确。结果是这样的:

在此处输入图像描述

问题是我想要格式“02/03/2022”而不是“2/3/2022” '

I want show date with this format DD/MM/YYYY. I need to use italian languages with data picker and this format DD/MM/YYYY.
In my app.module I do this:

export const DD_MM_YYYY_Format = {
  parse: {
      dateInput: 'DD/MM/YYYY',
  },
  display: {
      dateInput: 'DD/MM/YYYY',
      monthYearLabel: 'MMM YYYY',
      dateA11yLabel: 'LL',
      monthYearA11yLabel: 'MMMM YYYY',
  },
};

and after I do in my providers :

 { provide: MAT_DATE_LOCALE, useValue: 'it-IT' },
   {provide: MAT_DATE_FORMATS, useValue: DD_MM_YYYY_Format},

So I do in my component and the format is not properly correctly. the result is this:

enter image description here

the problem is that I want the format '02/03/2022' and not '2/3/2022'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2025-01-17 22:21:18

将日期管道添加到输入字段引用 angular.io/api/common/DatePipe

您似乎正在寻找这个管道:

{{ dateObj | date:'dd/MM/YYYY' }}  

Add a date pipe to your input field ref angular.io/api/common/DatePipe.

You seem to be looking for this pipe:

{{ dateObj | date:'dd/MM/YYYY' }}  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文