首页 > 解决方案 > 是否可以在对象内格式化日期?

问题描述

这样的事情可能吗?尝试格式化日期formatted_short

<Generic type="startDate" jsonldtype="DateTime" schema={{ 
  startDate: `${props.dates[0].start_date.formatted_short.format('YYYY-MM-DD')}`,
  endDate: `${props.dates[0].end_date.formatted_short}`,
  doorTime: `${props.dates[0].start_date.time}`,
}}/>

标签: javascriptreactjsjson-ld

解决方案


您可以使用 react-moment 格式化日期。

你可以这样使用;

import React  from 'react';
import Moment from 'react-moment';

export default class MyComponent extends React.Component {
    render() {
        return (
            // format : your format.
            <Moment format="YYYY/MM/DD">
                1976-04-19T12:59-0500 // your date string
            </Moment>
        );
    }
}

推荐阅读