问题描述
如何在 {{item.Date}} 内格式化日期
我得到了很多行,但我不知道一次将它们全部格式化
我认为将 MysqL 中的数据类型设置为 Date 可以解决它,但显然没有。
提前致谢!
我得到了什么
2021-03-18T23:00:00.00Z
我想要的
2021-03-15
我的代码
API
app.get('/schedetails/:schid',(_req,_res) => {
MysqLConnection.query('Select * from ScheDetails where Schedule_ID = ?',[_req.params.schid],(err,rows,_fields) => {
if (!err)
_res.send(rows);
else
console.log(err);
})
});
.ts 文件
getScheduleDetail(item){
this.http.get("http://localhost:3000" +"/schedetails/"+ item).subscribe(res=>{
console.log(res)
this.schedetaildata = res;
})
}
html
<div *ngFor="let item of schedetaildata">
<p>{{item.Weekday}}</p>
<p>{{item.Time_start}}</p>
<p>{{item.Time_finish}}</p>
<p>{{item.Date}}</p>
</div>
解决方法
您有一个 ISO 8601 日期字符串,并且由于位置是固定的,您知道您只需要前 10 个字符。
最简单的解决方案是使用 substring()
。
示例:
{{ item.Date.substring(0,10) }}