0

I'm using react-intl formatDate to convert the date.I need to get the date in "MM-DD-YYYY" format where as I'm getting it in "DD-MM-YYYY" format.Is there any specific way to achieve this?

    time value = {
        MyTime.createdTimestamp
    }
    aria - label = {
        formatDate(new Date(Number(MyTime.createdTimestamp)))
    } > {
        formatDate(new Date(Number(MyTime.createdTimestamp)), {
            year: 'numeric',
            month: 'numeric',
            day: 'numeric'
        })
    }
Aaqib
  • 9,942
  • 4
  • 21
  • 30
Hema Nandagopal
  • 668
  • 12
  • 35

2 Answers2

1

Try this:

new Intl.DateTimeFormat('en-US', {year: 'numeric', month: 'numeric',day: 'numeric'}).format(new Date(Number(MyTime.createdTimestamp)))
Rodius
  • 2,271
  • 14
  • 19
0
 const today = Date.now();    
 console.log(new Intl.DateTimeFormat('en-US', {year: 'numeric', month: '2-digit',day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).format(today));