one of the most common tasks when working in JavaScript and ReactJS. Fortunately, there are some powerful libraries available like date-fns or moment.js
Body
I want the result add day and month
Tags: convert, react js, javascript, react, date format
1 Replies
-
1. Get the original date: You can get the original date either as a Date object or a string.
2.Format the date: Use the format function from either date-fns or moment.js to specify how you want the date to be formatted.
3.Return the result: Return the converted date either as a Date object or string, depending on the format specified.
For example, using date-fns you could convert a standard date string to a custom-formatted string like so:
const originalDate = new Date(“December 31”); const convertedDate = format(originalDate, ‘dd-MM’);