简体   繁体   中英

Display two dates in react

I want to display two dates in my react application. It should be displayed as Date1 - Date2. Here is the code.

export const formatFromToDates = (fromDate, toDate) => { 
   return (
     <Moment format='YYYY/MM/DD'>{fromDate}</Moment> -
     toDate === null ? ' Now' : <Moment format='YYYY/MM/DD'>{toDate}</Moment>
    ); 
}

But is only displays the second date. How should I do this?

You've forgotten to put {} around your JSX expression for toDate :

export const formatFromToDates = (fromDate, toDate) => { 
    return (
        <Moment format='YYYY/MM/DD'>{fromDate}</Moment> -
        {toDate === null ? ' Now' : <Moment format='YYYY/MM/DD'>{toDate}</Moment>}
// -----^------------------------------------------------------------------------^
    ); 
};

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