【问题标题】:Changing the date format from DD-MM-YYYY to MM-DD-YYYY using react-intl使用 react-intl 将日期格式从 DD-MM-YYYY 更改为 MM-DD-YYYY
【发布时间】:2017-12-01 09:56:01
【问题描述】:

我正在使用 react-intl formatDate 转换日期。我需要以“MM-DD-YYYY”格式获取日期,而我以“DD-MM-YYYY”格式获取日期。有吗有什么具体方法可以实现吗?

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

【问题讨论】:

    标签: reactjs react-intl


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:
       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));
      

      【讨论】:

      • 口头解释这段代码的作用会有所帮助
      • 另外,考虑编辑代码以跨多行发送垃圾邮件,这样用户就可以在屏幕上看到完整的代码,而无需滚动。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      相关资源
      最近更新 更多