只显示一天的相对时间?
Display Relative Time for just one day?
我使用 dayJS 并且只想显示一天的相对时间 - 24 小时
有没有办法自定义 fromNow() 只显示一天?
例子
currentDate = 'Sun Aug 15 2021 15:03:09 GMT+0300';
oldDate = 'Fri Aug 13 2021 15:03:09 GMT+0300';
created_at = dayjs(currentDate).fromNow(true) => 17 min 2 sec // ok ✅
// if +=1 day
created_at =
dayjs(oldDate).fromNow(true) => 2 day // hidden this one
这是我试过的解决方法:)
如果有任何其他解决方案,请告诉我:)
let acceptedDate = ['few seconds', 'minute', 'minutes', 'hour', 'hours'];
let currentDate = dayjs();
let targetedDay = created_at;// from api
let currentRelativeTime = dayjs(targetedDay).from(currentDate, true);
let timeArr = currentRelativeTime.split(' ');
let isAcceptedDate = acceptedDate.some(item => timeArr.includes(item));
console.log(isAcceptedDate);
我使用 dayJS 并且只想显示一天的相对时间 - 24 小时
有没有办法自定义 fromNow() 只显示一天?
例子
currentDate = 'Sun Aug 15 2021 15:03:09 GMT+0300';
oldDate = 'Fri Aug 13 2021 15:03:09 GMT+0300';
created_at = dayjs(currentDate).fromNow(true) => 17 min 2 sec // ok ✅
// if +=1 day
created_at =
dayjs(oldDate).fromNow(true) => 2 day // hidden this one
这是我试过的解决方法:) 如果有任何其他解决方案,请告诉我:)
let acceptedDate = ['few seconds', 'minute', 'minutes', 'hour', 'hours'];
let currentDate = dayjs();
let targetedDay = created_at;// from api
let currentRelativeTime = dayjs(targetedDay).from(currentDate, true);
let timeArr = currentRelativeTime.split(' ');
let isAcceptedDate = acceptedDate.some(item => timeArr.includes(item));
console.log(isAcceptedDate);