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

时间:2017-12-01 09:56:02

标签: reactjs react-intl

我使用react-intl formatDate来转换日期。我需要在" MM-DD-YYYY"中获取日期。格式在哪里我可以得到它" DD-MM-YYYY" format.Is有什么特定的方法来实现这个目标吗?

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

2 个答案:

答案 0 :(得分:1)

试试这个:

new Intl.DateTimeFormat('en-US', {year: 'numeric', month: 'numeric',day: 'numeric'}).format(new Date(Number(MyTime.createdTimestamp)))

答案 1 :(得分: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));