使用 moment React 格式化日期

Format date using moment React

我已经创建了 ** React 组件**

class Test extends Component{

state = {
    birthdate: '2020-09-20'
}

render(){
    const {birthdate} = this.state;
    const mdiffInDays = moment(moment()).diff(moment(birthdate), 'days');
    const mdiffInWeeks = moment(moment()).diff(moment(birthdate), 'weeks');

    return(
    <div className="card">
        <span>Today: {moment(moment()).format('DD MMM YYYY')}</span>
        <span>Birthdate: {birthdate}</span>
        <span>Days: {mdiffInDays}</span>
        <span>Weeks: {mdiffInWeeks}</span>           
    </div>            
    )
}}

我有两个问题:

  1. 今天 - 如何使用 "PL" region 而不是 23-Oct-2020
  2. 生日 呈现为:YYYY-MM-DD。如何将其更改为 display "DD-MM-YYY"?

我正在学习 React,现在尝试玩转日期。

const birthdate =  '2020-09-20'
const date = new Date(birthdate)
const options = {
  year: "numeric",
  month: "short",
  day: "numeric",
};
console.log(date.toLocaleDateString("pl", options));