Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  100] [ 3]  / answers: 1 / hits: 14338  / 3 Years ago, mon, january 18, 2021, 12:00:00

I'm building a DatePicker React with the Material-UI picker library and using Luxon as an adapter.
When I change the calendar date I'm getting an object with DateTime as follow:


Image


The code I'm using of the DatePicker:


<MuiPickersUtilsProvider utils={LuxonUtils}>
<DatePicker
className={classes.input}
disableToolbar
variant="inline"
label="Date"
format="cccc, LLLL dd"
helperText=""
value={date}
margin="normal"
onChange={newDate => {
handleDateOnChange({ newDate });
setDate(newDate);
}}
inputVariant="filled"
fullWidth
minDate={new Date()}
/>
</MuiPickersUtilsProvider>

The `on change is giving me back the OBJ I shared in the screenshot and what I would like to get is the date.


I'm doing a console.log(newDate) inside the handleDateOnChange and there is no more inside that why I'm not sharing that. The result of console.log() is the one you see above.


More From » reactjs

 Answers
5

You can simply use toJSDate()



Returns a Javascript Date equivalent to this DateTime.





const DateTime = luxon.DateTime;
const dt = DateTime.local();
console.log(dt);
console.log(dt.toJSDate());

<script src=https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js></script>




[#1938] Wednesday, January 13, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isaacvalentinn

Total Points: 325
Total Questions: 120
Total Answers: 131

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
isaacvalentinn questions
;