我不明白为什么现在的日期是2020年7月11日,但是下一个代码不起作用:
class LoginBox extends React.Component<>{
...
// Hide navigation bar in login page. Do it inside ComponentDidMount as we need to wait for navbar to render before hiding it.
componentDidMount(){
document.getElementById('navigation-bar')!.style.display = "none";
}
componentWillUnmount(){
document.getElementById('navigation-bar')!.style.display = "flex";
}
render(){
return(
// your login/signup component here
...
)
}
}
答案 0 :(得分:1)
检查给定日期是否等于当前日期
const isToday = (date) => {
const today = new Date();
return date.getDate() === today.getDate() &&
date.getMonth() === today.getMonth() &&
date.getFullYear() === today.getFullYear();
};
console.log(isToday(new Date('2020/07/14')));
console.log(isToday(new Date('2020/07/11')));