使用 react-intl 将日期格式从 DD-MM-YYYY 更改为 MM-DD-YYYY

Changing the date format from DD-MM-YYYY to MM-DD-YYYY using react-intl

我正在使用 react-intl formatDate 转换 date.I 需要以 "MM-DD-YYYY" 格式获取日期,而我在 "DD-MM-YYYY" [=16= 中获取日期] 有什么具体的方法可以实现吗?

    time value = {
        MyTime.createdTimestamp
    }
    aria - label = {
        formatDate(new Date(Number(MyTime.createdTimestamp)))
    } > {
        formatDate(new Date(Number(MyTime.createdTimestamp)), {
            year: 'numeric',
            month: 'numeric',
            day: 'numeric'
        })
    }

试试这个:

new Intl.DateTimeFormat('en-US', {year: 'numeric', month: 'numeric',day: 'numeric'}).format(new Date(Number(MyTime.createdTimestamp)))
 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));