srikanth
srikanth

Reputation: 3

Javascript Date Display in DatePicker

I have a response from the server as 01 Jun 2020. It Displays as a placeholder in DatePicker. But I need to display it as 01/06/2020.

this.setState({ 
    start_date: responseJsonFromServer.start_date      
});

Here start_date is 01 Jun 2020. Need to convert as 01/06/2020. Please Help me

Upvotes: 0

Views: 41

Answers (2)

yesIamFaded
yesIamFaded

Reputation: 2068

Try out MomentJS it is an easy package to use and it lets you format your date like you want.

const date = new Date();

const formattedDate = Moment(date).format("DD/MM/YY")

this will show you the desired format. Check out momentjs because it has some very cool features like adding and subtracting from that date for example.

https://momentjs.com/

Upvotes: 1

Michael Mishin
Michael Mishin

Reputation: 571

Send prop with format to your date picker:

format="DD/MM/YYYY"

Upvotes: 0

Related Questions