我使用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'
})
}
答案 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));