Reactjs 使用react intl将日期格式从DD-MM-YYYY更改为MM-DD-YYYY
我正在使用react intl formatDate转换日期。我需要以“MM-DD-YYYY”格式获取日期,而我以“DD-MM-YYYY”格式获取日期。是否有任何具体方法来实现此目的Reactjs 使用react intl将日期格式从DD-MM-YYYY更改为MM-DD-YYYY,reactjs,react-intl,Reactjs,React Intl,我正在使用react intl formatDate转换日期。我需要以“MM-DD-YYYY”格式获取日期,而我以“DD-MM-YYYY”格式获取日期。是否有任何具体方法来实现此目的 time value = { MyTime.createdTimestamp } aria - label = { formatDate(new Date(Number(MyTime.createdTimestamp))) } > {
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));