簡體   English   中英

顯示兩個日期

[英]Display two dates in react

我想在我的應用程序中顯示兩個日期。 它應顯示為Date1-Date2。 這是代碼。

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

但是只顯示第二個日期。 我應該怎么做?

您忘了在{}周圍加上toDate的JSX表達式:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM