【问题标题】:Angular date format based on locale基于语言环境的角度日期格式
【发布时间】:2019-08-10 02:43:28
【问题描述】:

我有一个 Angular 2 应用程序,其中几乎没有日期类型的输入。默认情况下,这些日期以MM/dd/YYYY 格式显示。我需要它们的格式为dd.MM.YYYY。我很喜欢这可以在app.module.ts 中设置,以便您指定具有这种格式的区域。 应该完成这项工作的代码是:

@NgModule({
 .
 .
 .
  providers: [AuthGuard, {provide: LOCALE_ID, useValue: 'sl'}],
  bootstrap: [AppComponent]
})

这是我要格式化的 HTML 部分

<div class="col-lg-3">
  <fieldset class="form-group">
    <label>Birth date:</label>
    <div class="form-group input-group">
      <div class="input-group-append">
        <span class="input-group-text">
          <i class="fa fa-birthday-cake" aria-hidden="true"></i>
        </span>
      </div>
      <input class="form-control" type="date" [ngModel]="birthDate" />
    </div>
  </fieldset>
</div>

有人知道为什么这不起作用吗?

【问题讨论】:

标签: angular date format date-format


【解决方案1】:

经过长时间的研究,我发现我们无法更改&lt;input type="date"&gt;的显示格式。更改它的唯一方法是将 chrome 设置更改为使用本地语言。为了归档我尝试的内容,您必须使用日期选择器。
这是一个例子:
Angulat material date picker
如需更详细地了解 Chrome 对我的问题的回答,请点击此处的链接(该注释来自 2012 年,但它仍然可以正常工作):
Chrome and input type date
谢谢大家的时间

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-04
    • 2014-03-16
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    • 2023-04-03
    相关资源
    最近更新 更多