在 React Redux 中保存选定的日期而不是 utc 日期

Save selected date and not utc date in react redux

我尝试关注 and find a solution with the help of

这个 had a part of the information that I need but it did not provide me with an answer. This几乎有我想要的但是redux不让我通过状态下的输出日期

我正在使用 redux (typescript v. ^3.8) 编写一个 React 应用程序,并且有一个使用“react-datepicker”npm 包版本的 dateTimePicker 组件:v.2.15。我 select 来自选择器的值,假设是 07/07/2020,但是当我将它保存在带有减速器的状态时,

action.payload 的类型为 2020 年 7 月 7 日星期二 00:00:00 GMT+0300(东欧夏令时)

但在状态中我现在有 2020-07-06T21:00:00.000Z.

我的理解是 属性 正在保存的日期是日期类型,但格式“YYYY-MM-DDTHH:mm:ss.SSSZ”是 utc 中的 ISOstring() .

如何在不考虑 local/utc 日期和时区的情况下仅传递州内的 selected 值 (07/07/2020)?我的目标是这个 2020-07-07T00:00:00.000Z

在我的 reducer 中,我应该如何操作日期以获得上述结果?我的代码片段是这样的:

export const changeGeneralFormDateReducer = (
  state: IState,
  action: IAction<Date>
): IState =>
  produce(state, (draftState: IState) => {   
    draftState.generalForm.Date = action.payload;    
  });

使用这样的东西

draftState.generalForm.Date = new Date(
    Date.UTC(
      action.payload.getFullYear(),
      action.payload.getMonth(),
      action.payload.getDate()
    )
  );