0

I'm trying to convert the date today to a specific format

Hoping to achieve the format (dd mm yyyy) and the month is the shortened version in string format:

03 Apr 2022

I tried to do the following:

const dateToday = new Date()

const options = {
    year: 'numeric', month: 'short', day: 'numeric'
}

console.log(dateToday.toLocaleDateString('en-US', options))

The output I get is

Apr 3, 2022

Any recommendations I can take?

KiritoLyn
  • 626
  • 1
  • 10
  • 26
  • 1
    Please try this: `console.log(\`${dateToday.toLocaleDateString({}, { day: '2-digit' })}-${dateToday.toLocaleDateString({}, { month: 'short' })}-${dateToday.toLocaleDateString({}, { year: 'numeric' })}\`);` – jsN00b Apr 02 '22 at 16:28
  • 1
    With a little modification, I got the answer I needed. Thanks for this. – KiritoLyn Apr 02 '22 at 16:36

0 Answers0