-1

我正在使用角度垫日期输入,在 MomentDateAdapter 解析日期我想将输入数字转换为特定的日期格式。例如

     |  Input |InpurtFormat|OutputFormat|  Output  |
     |-------:|-----------:|-----------:|---------:|
     |21102012|  DDMMYYYY  | DD/MM/YYYY |21/10/2012|
     |12212020|  MMDDYYYY  | MM/DD/YYYY |12/21/2020|
     |20201221|  YYYYMMDD  | YYYY/MM/DD |2020/12/21|
    parse(value: any, parseFormat: string | string[]): Moment | null {
        if (value && typeof value === 'string') {
            const format = this._dateTimeService.getFormat();
            return moment.utc(value, format, this.locale, true);
        }
        return value ? moment.utc(value).locale(this.locale) : null;
    }
4

1 回答 1

0

有了片刻,您就可以这样做

  const x = moment(date).format("D/M/yyyy");
于 2021-10-19T11:12:02.187 回答