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



如何更改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);
}
}

最新更新