I am new in react. I need use react-datepicker
I want to get value of input, when I change date. If i click on 20th October 2017, i want put 20th October 2017 in my vari
You can use the getTime() helper function on your date object to get the millisecond timestamp for that specific date, which is a JavaScript number data type. Useful for saving data in the backend of your application. For example Flask Peewee ORM requires a timestamp to be saved for the DateTimeField.
const [startDate, setStartDate] = useState(new Date())
{
setStartDate(getTime(date))
}
/>
source: https://date-fns.org/v2.0.0-alpha.7/docs/getTime
Combine it with an effect to set the default state value to a timestamp on page load:
useEffect(() => {
setStartDate(getTime(startDate))
}, [])
Otherwise for your UI, you can use the format() helper function to get the string value of the given object, with any given format:
{format(startDate, "MMMM d, yyyy h:mm aa")}
source: https://date-fns.org/v2.0.0-alpha.7/docs/format