How to Convert a string date to a more readable version

I have a date in my database like this 2021/04/26

And I wanna convert this to string date to: Monday, April 04

I have tried In many different ways. I am very week in working with dates in JavaScript .

I tried to do like this new Date('2021/04/26').getDate() // Which return very strange date.

Can Anyone help me to convert that string to this Monday, April 04

Answer

Method 1: By using only the build in functions this is the closest you can get to your example:

new Date('2021/04/26').toDateString()

Method 2: Do it on your own like this:

  const months = {
  0: 'January',
  1: 'February',
  2: 'March',
  3: 'April',
  4: 'May',
  5: 'June',
  6: 'July',
  7: 'August',
  8: 'September',
  9: 'October',
  10: 'November',
  11: 'December'
}

const days = [
  'Sunday',
  'Monday',
  'Tuesday',
  'Wednesday',
  'Thursday',
  'Friday',
  'Saturday'
]

let yourDate = new Date('2021/04/26');
let yourDateString = days[yourDate.getDay()]+', '+months[yourDate.getMonth()]+' '+yourDate.getFullYear();

RESULT: “Monday, April 2021”

Method 3: Use a third party library.