我有一个表格,其中一个输入类型是日期,日期被写为“dd/MM/yyyy”,但我发布的 API 只接受日期为“MM/dd/yyyy”。有人可以向我解释如何在将此日期发送到 API 之前对其进行转换。我正在使用角度 15.
我的组件看起来像这样:
criarInternacao(){
this.service
.postInternacao(this.dateToBeFormated)
.subscribe((data:any) => {
console.log('success')
)
})
}
我的服务是这样的:
public postInternacao(dateToBeFormated?:any){
const token = this.token.retornaToken();
const headers = new HttpHeaders({ Authorization: `Bearer ${token}` });
return this.http.post(
`${APIINTERNACAO}/add-date/&dateToBeFormated=${dateToBeFormated}`,
{
dateToBeFormated:dateToBeFormated,
},
{ headers, observe: 'response' }
)
}