Reputation: 3
I'm getting my backend date as follows:
2020-01-01T03:00:00.000Z
I am using the daterangepicker from the AdminLTE template.
my field:
<div className="col-sm-3">
<label>Contratação *</label>
<Field
name="dt_contracting"
type="date"
className="form-control"
/>
</div>
I want to convert the received date, to the format "DD/MM/YYYY"
my input is already in the correct format to select, but when I receive the Back-End date, it is not filled due to difference in format.
Upvotes: 0
Views: 2393
Reputation: 7542
Easiest way is to use the built-in toLocaleDateString()
function. MDN
In your case you can use it like this:
function toPrettyDate( rawDateStr ) {
const date = new Date( rawDateStr );
return date.toLocaleDateString('en-GB'); // Should really use user-based locale here
}
Upvotes: 2
Reputation: 744
You can use momentjs.
Prefer this for installation https://www.npmjs.com/package/react-moment
https://momentjs.com/docs/ for examples
Upvotes: 0