反应矩解析ISO 8601可读格式的剩余时间

问题描述 投票:0回答:1

我正在尝试从eBay API中获取'timeLeft字段,并将其转换为看起来很正常的内容,例如剩余3小时,10分钟和5秒。

数据看起来像这样:P3DT6H28M15S

我正在尝试使用React Moment模块,但无法确切地知道如何执行此操作。

这是我最新的测试:

 <Moment format="h:mm:ss">
                {card.sellingStatus && card.sellingStatus[0].timeLeft}
              </Moment>

但是这将返回'无效日期'。

我也尝试下面的代码只是为了查看HTML输出是什么样,但是我正在尝试其他输出字段

<Moment>{card.listingInfo && card.listingInfo[0].endTime}</Moment>

请注意endTime看起来像这样

2019-11-09T19:45:32.000Z

但是上面的代码为每个项目生成了相同的确切值

Tue Jan 01 2019 00:00:00 GMT-0500

即使所有endTime字段都不相同

关于我在这里可能做错什么的任何想法?

reactjs momentjs ebay-api
1个回答
0
投票

因此,我通过使用react-timeago npm模块基本上完成了我所需要的。

 <TimeAgo
                date={new Date(
                  card.listingInfo && card.listingInfo[0].startTime
                ).toLocaleDateString()}
              />
© www.soinside.com 2019 - 2024. All rights reserved.