Angular-以字符串形式获取格式,用于根据语言环境显示日期

Val*_*ert 5 angular-date-format angular

如何获取Angular用于显示日期的字符串形式的格式?我用的是date管道设置后,LOCALE_ID在我的app.module

现在,我想检索“ dd / mm / yyyy”字符串,以放入我的输入占位符。

基本上,这里描述的只是Angular。

谢谢

[编辑]

为了使它更明确,我没有在寻找一种格式化日期的方法,这种方法已经完成了(使用本机date管道)。我想要代表此管道正在使用的格式的字符串。

因为我希望我的日期选择器占位符像

“日期(格式:XXXXXX)”

我希望“ XXXXXX”部分正确(例如,法语为“ jj / mm / aaaa”,英语为“ mm / dd / yyyy”)

Sim*_*mon 5

希望在此期间,您遇到过getLocaleDateFormat()和getLocaleTimeFormat()。(角度6)

import { getLocaleDateFormat, FormatWidth } from '@angular/common';
export class Foobar {
  constructor( @Inject( LOCALE_ID ) private locale: string ) { }

  private getDateFormat() {
    return getLocaleDateFormat( this.locale, FormatWidth.Short );
  }
}
Run Code Online (Sandbox Code Playgroud)