const CurrentDate = (props) => {
return (
<div>
{ /* change code below this line */ }
<p>The current date is: {Date()}</p>
{ /* change code above this line */ }
</div>
);
};
When I try to do {new Date()}, I get an error in the console. And just doing {Date()} gives me the string Thu Aug 06 2020 02:56:45 GMT+0500 (Pakistan Standard Time). How do I get the just the date? I tried calling the functions from Date, but that also gave errors.
This is what I have for Calendar right now:
class Calendar extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h3>What date is it?</h3>
{ /* change code below this line */ }
<CurrentDate date="date" />
{ /* change code above this line */ }
</div>
);
}
};
But yeah, to pass the challenge, I just had to do date={Date()}. I’m still curious as to how I can get the getDate version to work though. Even if it wouldn’t pass the challenge.
I see. It’s a good thing then, as you’ll get more insight by testing this. I will give you some hints. But you should be confindent and find out the rest for yourself.
Try this code…
const CurrentDate = (props) => {
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return (
<div>
{ /* change code below this line */ }
<p>The current date is: day: {props.date.getDate()}</p>
<p> The current year is {props.date.getFullYear()}
</p>
<p> The current month is {months[props.date.getMonth()]}
</p>
{ /* change code above this line */ }
</div>
);
};
class Calendar extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h3>What date is it?</h3>
{ /* change code below this line */ }
<CurrentDate date={new Date}/>
{ /* change code above this line */ }
</div>
);
}
};