我如何格式化CoreUI数据表中的日期时间

问题描述

我应该设置日期时间的格式以显示“ 2020年9月28日00:11”。

我的初始值是“ 2020-09-28 00:11:50”。

当前,这就是它的显示方式。

enter image description here

我正在使用coreui的数据表。

这是我用于数据表分配的代码

enter image description here

我想知道是否可以在这里格式化日期时间?

解决方法

你可以试试这个:

createdAt: (item: any) => (
    <td>
        <Moment format="DD.MM.YYYY">{item.createdAt}</Moment>
    </td>
)

Datatable 有 scoppedSlots 道具可以更改任何范围,我使用 react-moment 进行日期格式化。