【发布时间】:2019-10-28 14:16:09
【问题描述】:
我正在构建这个从数据库中获取文章的应用程序,其中 1 个字段是现在格式为“2019-06-13T18:03:58.000Z”的日期 基本上我需要做的是检查这是否是今天的日期返回仅小时和上午/下午所以对于这个例子是今天所以返回下午 18:03,如果日期与昨天相同则返回“昨天”如果日期不是那些然后返回'月,日'
我尝试过创建 Date 对象,然后进行比较,但没有成功
我有这个html代码:
<div class='date-container'>
{{renderDate(data.created_at)}}
</div>
在component.ts文件中:
public renderDate(date) {
const fecha = new Date(date);
const today = new Date();
const yesterday = today.getDate()-1;
let fecha_r = '';
if(fecha.getTime() == today.getTime()){
fecha_r = 'today';
}
return fecha_r;
}
我需要在该函数中返回转换后的日期,以便我的 html 代码打印正确的格式化日期我该怎么做?
【问题讨论】:
标签: javascript angular date angular8