'Extracting month,day and year in react with date.toLocaleString not working
I am building a react app and i am trying to extract the month,day and year in react with date.toLocaleString and my website is crashing,showing a blank page, and it isn t showing my components.This should output the month(e.g august), the year (e.g 1967) and the day (e.g 15)
function ExpenseDate(props) {
const month = props.date.toLocaleString("en-US", { month: "long" });
const day = props.date.toLocaleString("en-US", { day: "2-digit" });
const year = props.date.getFullYear();
return (
<div>
<div>{month}</div>
<div>{day}</div>
<div>{year}</div>
</div>
)
}
Solution 1:[1]
did you call props in ExpenseItem(i suppose)? try doing this between div's .
<ExpenseDate date={props.date} />
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mihajlo Markovic |