在将日期发送到API之前,请使用
formatDate()
.
别忘了导入它:
import { formatDate } from '@angular/common';
constructor(@Inject(LOCALE_ID) private locale: string) {}
myDate;
bsConfig;
ngOnInit() {
this.bsConfig = {
containerClass: 'theme-red',
dateInputFormat: 'MM-dd-yyyy'
};
}
sendDataToApi() {
const date = formatDate(this.myDate, this.bsConfig.dateInputFormat, this.locale);
howeverImSendingDataToApi(whateverData, date);
}