ant-design,解决格式化Table中的时间

使用React+Antd遇到的Table组件时间格式化的问题

我在开发react项目时使用antdUI进行开发,遇到了对时间格式化的问题,下面是我成功格式化的解决办法

在使用antd的时候要想修改table里面的内容需要用到render属性

 这里使用的moment 。使用前请先安装 yarn add moment 

代码如下

// 我这边是hooks
import moment from 'moment';
export default (props: any) => {
  const formatterTime = (val) => {
    return val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : '';
  };
  const columns: any = [
    {
      title: `${entryName}`,
      dataIndex: 'projectName',
      key: 'projectName',
      ellipsis: true,
    },
    {
      title: `${t('created-by')}`,
      dataIndex: 'creatorName',
      key: 'creatorName',
      ellipsis: true,
    },
    {
      title: `${creationTime}`,
      dataIndex: 'created',
      key: 'created',
      ellipsis: true,
      render: formatterTime, //在这里调用就可以实现时间格式化
    },
    {
      title: `${type}`,
      dataIndex: 'status',
      key: 'status',
      render: (text) => (
        <span>
          {/* 0 已发布,1 待审核,2 已退回*/}
          {text == '0'
            ? `${t('published')}`
            : text == '1'
            ? `${t('pending-approval')}`
            : `${t('returned')}`}
        </span>
      ),
    },
    {
      title: `${t('bottom-operation')}`,
      dataIndex: 'operation',
      key: 'operation',
      align: 'center',
      width: 280,
      render: (_, record) => (
        <Space size="middle">
          <a className="see border_bottom">{t('pass')} </a>
          <a className="close border_bottom">{t('return')}</a>
          <a className="see border_bottom" onClick={() => onSee(record)}>
            {t('see')}
          </a>
          <a className="close border_bottom">{t('close')}</a>
          <a
            className="codeWord border_bottom"
            onClick={() => onPasswordSet(record)}
          >
            {t('password-set')}
          </a>
        </Space>
      ),
    },
  ];
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jim-zf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值