如何在时刻设置日期?

Adw*_*hna 2 javascript node.js momentjs reactjs

我想将日期设置为另一天,然后在日期上加 1。

    onModalPrevDate=()=>{
        this.closeModal();
        let d=this.state.selectedDay;
        let dateContext = Object.assign({}, this.props.dateContext);
        let c=moment(dateContext).set("days",d);  //not working as intended
        let f=moment(c).add(1,"day");
        let a=f.format("D");
        this.onDayClick(a);
    }
Run Code Online (Sandbox Code Playgroud)

时刻(dateContext).set("days",d); 没有按预期工作。尝试过“day”而不是“days”仍然无效。

Adw*_*hna 14

使用“日期”而不是“天”

let c=moment(dateContext).set("date",d); 
Run Code Online (Sandbox Code Playgroud)

  • 对于那些想知道的人,[`day`](https://momentjs.com/docs/#/get-set/day/) 设置星期几 (0-6) (3认同)