【问题标题】:ReactJS - How to convert the date format inside an array of hash?ReactJS - 如何在哈希数组中转换日期格式?
【发布时间】:2021-02-26 12:32:28
【问题描述】:

在反应应用程序(nextjs)中,我想使用 moment 转换 date 格式,该格式位于哈希数组下。数据就像,

 [
    {
      "date": "2020-12-22T00:00:00.000Z",
      "price": "4365.6384226722"
    },
    {
      "date": "2020-12-23T00:00:00.000Z",
      "price": "4084.628672025"
    },
    {
      "date": "2020-12-24T00:00:00.000Z",
      "price": "3874.3753251552"
    },
   ...
 ]

const formatDate = (value) => {
  return moment(value).format('HH:MM A DD MM, YYYY')
}

在这里,我想使用formatDate 更改date 格式并以相同的数据格式返回它,我想将它传递给图形。 请帮忙解决这个问题。

【问题讨论】:

    标签: javascript arrays reactjs momentjs next.js


    【解决方案1】:

    你是说这个?

    const passedValue = yourArray.map(item => ({
        date: formatDate(item.date),
        price: item.price
    }))
    

    【讨论】:

      猜你喜欢
      • 2015-11-26
      • 2010-12-11
      • 1970-01-01
      • 2012-10-29
      • 2017-07-05
      • 2019-10-27
      • 2019-05-23
      • 1970-01-01
      • 2021-08-28
      相关资源
      最近更新 更多