angular 的 getLocaleDateTimeFormat 函数返回 {1}、{0}

Sak*_*ken 5 javascript angular

我正在使用 angular 的 getLocaleDateTimeFormat 函数在输入字段中显示选定的日期时间。

getLocaleDateTimeFormat(this.injector.get(LOCALE_ID), FormatWidth.Short) 功能显示 {1}, {0}

但是当我使用
getLocaleDateFormat(this.injector.get(LOCALE_ID), FormatWidth.Short),并getLocaleTimeFormat(this.injector.get(LOCALE_ID), FormatWidth.Short)各自独立,他们显示日期和时间正确。

难道我做错了什么?

我的功能是:

`格式化日期(日期:日期):字符串{

if (!date || typeof date == 'string') {
    return '';
}

let localeId = this.injector.get(LOCALE_ID);

let localeDateFormat = getLocaleDateFormat(localeId, FormatWidth.Short);
let localeTimeFormat = getLocaleTimeFormat(localeId, FormatWidth.Short);
let localeDateTimeFormat = getLocaleDateTimeFormat(localeId, FormatWidth.Short);
return formatDate(date, localeDateTimeFormat, localeId);
Run Code Online (Sandbox Code Playgroud)

}`

问题是 getLocaleDateTimeFormat 函数没有从日期参数中获取日期或时间或两者

Wil*_*mer 0

如果您正在寻找的是模板,例如“YYYY/MM/DD”,则导入区域设置数据:

import localeDe from "@angular/common/locales/de";
...
localeDe[10][FormatWidth.Short]
Run Code Online (Sandbox Code Playgroud)

数组中有四个成员对应FormatWidth enum {Short, Medium, Long, Full}