繁体   English   中英

如何更改 datepiker 材料中的日期格式是有角度的?

[英]How to change the date format in datepiker material is angular?

如何更改 datepiker 材料中的日期格式是有角度的,数据以完整格式发送到后面,您需要 01/01/2020 - 通过点

在您的组件中

import { CustomDataAdapter } from 'path.........';

@Component({
  selector: 'some-selector',
  templateUrl: './some-selector.component.html',
  styleUrls: ['./some-selector.component.scss'],
  providers: [
    { provide: DateAdapter, useClass: CustomDataAdapter}
  ],
})

自定义日期适配器

import { Injectable } from "@angular/core";
import { NativeDateAdapter } from "@angular/material/core";

@Injectable()
export class CustomDataAdapter extends NativeDateAdapter {
    format(date: Date, displayFormat: Object): string {
        if ( displayFormat['year'] == "numeric" && displayFormat['month'] == "numeric" && displayFormat['day'] == "numeric" ){
            const seperator = ".";
            return `${date.getDate().toString().padStart(2, '0')}${seperator}${(date.getMonth() + 1).toString().padStart(2, '0')}${seperator}${date.getFullYear()}`;
        }
        return super.format(date, displayFormat);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM