I use the Material-UI pickers library to get the date And I just want to get the date like this 17/07/2021
But I get both the date and the time like this Sat Jul 17 2021 12:21:00
const [getDate, setGetDate] = useState(new Date());
<DatePicker
value={selectedDate}
format="MM/dd/yyyy"
minDate={new Date()}
onChange={handleDateChange}
label="Date"
size="small"
required
fullWidth
inputVariant="outlined"
animateYearScrolling
/>
Can you help me please?
You can use formatter like moment for your case, something like this:
import moment from "moment";
...
let date = getDate; // value from your state
let formattedDate = moment(date).format('DD/MM/YYYY');
console.log(date) // before: Sat Jul 17 2021 12:21:00
console.log(formattedDate) // after: 17/07/2021
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With