【问题标题】:How to change input date in `French` instead of `English`?如何更改“法语”而不是“英语”的输入日期?
【发布时间】:2019-04-04 02:10:14
【问题描述】:

我正在设置一个输入日期,我用 chrome 用法语输入日期,但用 Internet Explorer 用英语输入它!我希望全部都是法语!

我希望输出是法语日历,但是当我使用 i.e 时,我得到的是英语日历!在 chrome 中它是法语,正如预期的那样!

【问题讨论】:

  • <html lang="fr"> 在您的 html 标记中。
  • 你指的是法语输入日期格式吗?

标签: html css angular


【解决方案1】:

Angular 具有内置的 i18n(国际化),您可以使用它来格式化日期、数字并为您的应用程序提供多语言描述。 https://angular.io/guide/i18n

如果我理解清楚的话,您的具体问题是关于以特定格式显示日期(例如 DD/MM/YY 而不是 MM/DD/YY)。你当然可以使用 DatePipes 和一些 i18n 配置来做到这一点:

src/app/app.module.ts

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';

// the second parameter 'fr' is optional
registerLocaleData(localeFr, 'fr');

来自角度docs

DatePipe、CurrencyPipe、DecimalPipe 和 PercentPipe 使用语言环境 data 根据 LOCALE_ID 格式化数据。

所以,只需将DatePipe 用作:

<p>Today is {{today | date}}</p>

你应该看到诀窍了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多