How to Convert Date from React-DatePicker into String

Viewed 2444

I want to convert Date into String format. First I want to get Date from react-datePicker and only want to convert it into single String UTC to String format "22-10-2020"

3 Answers

On your onChange event, you can get e.target.value and use like it new Date(e.target.value).toISOString().split('T')

if you want to convert the Date into string format then use toLocaleDateString() with the date i.e new Date().toLocaleDateString(); // 26-11-2020. <- string

You can Do This Things with use of Moment , You can Easyly switch you format and also play with date and time type. Moment js is Easy Way to play with such thing .

Related