简体   繁体   中英

How do I format the datetime in coreui datatable react

I am supposed to format the date time to display "28 Sep 2020 00:11".

my initial value is this "2020-09-28 00:11:50".

currently, this is how it is being displayed.

在此处输入图片说明

i am using coreui's datatable.

this is my code for the datatable assigning.

在此处输入图片说明

I want to know if there's any way i can format the datetime here?

You can try this:

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

Datatable has scoppedSlots prop for change any scop, I used react-moment for date formatting.

Detail I implement with good anwers @Kelvin Schoofs,@calal_mnf:

scopedSlots = {{
                'createdAt':
                  (item)=>(
                    <td>
                      <Moment format="DD/MM/YYYY hh:mm:ss">{item.createdAt}</Moment>
                    </td>
                  )
              }}

and

import Moment from 'react-moment';

This work for me ! Hope it useful for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM