简体   繁体   中英

How to format datetime using react-moment library

I want to format date and time by having string value. Therefore, I want my property to hold a formatted date and time using a library react-moment and return the local time. All this must be a function which I'll callback in my table. How could I make this?


import * as React from 'react';

type Props = {
    value: string;
};

const DateTimeColumn = (props: Props) => {
    const { value } = props;
    // TODO:
}

You can simply return the converted date like so:

import Moment from 'react-moment';

const DateTimeColumn = (props: Props) => {
    const { value } = props;
    return (
       <Moment format="YYYY/MM/DD" date={value} />
    )
}

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