function NoticeList({ title, dates }) {
let today = new Date();
let year = today.getFullYear();
let month = today.getMonth() + 1;
let date = today.getDate();
let formetToday = `${year}-${month < 10 ? `0${month}` : month}-${
date < 10 ? `0${date}` : date
} `;
let formetDates = moment(dates).format('YYYY-MM-DD');
console.log(date && formetToday === formetDates);
return (
<NoticeListContainer>
<NoticeLists>
{formetDates === formetToday ? <div>New</div> : null}
<h5>{title}</h5>
<div>{formetDates}</div>
</NoticeLists>
</NoticeListContainer>
);
}
export default NoticeList;
I would like to receive the data of the announcement and compare the date of the announcement with today's date to print out the new phrase. However, after comparing it with console.log, it all shows false. What's the reason? And if there's any other good way than this, please let me know.