在 react-redux 中使用日期选择器比较两个日期

Compare two dates using datepicker in react-redux

我有一个 DateInput 组件,我在我的 redux 表单中使用它:

const MyDatePicker = ({ input, meta: { touched, error } }) => (
  <div>
    <DatePicker
      {...input} dateFormat="DD-MM-YYYY"
      selected={input.value ? moment(input.value, 'DD-MM-YYYY') : null}
    />
    {touched && error && <span>{error}</span>}
  </div>
);

如何比较此组件产生的两个日期?我正在尝试 moment.js 的 isAfter 函数,但没有用

要比较两个日期对象,您可以将日期转换为 Unix 时间戳。 Unix 时间戳是从 1970 年 1 月 1 日开始的秒数(毫秒)。你将有两个 int,你可以简单地比较它们。

https://momentjs.com/docs/#/displaying/unix-timestamp/

此问题与 redux-form 无关。这只是一个一般的日期比较问题。 Moment 可以为您做到。你只需要弄清楚怎么做。

const withinAYear = moment(start).add(1, 'year').isAfter(moment(end))