How to set time with date in momentjs

后端 未结 5 2033
失恋的感觉
失恋的感觉 2021-02-02 05:19

Does momentjs provide any option to set time with particular time ?

5条回答
  •  面向向阳花
    2021-02-02 06:12

    Since this pops up in google results, moment now has a set(unit, value) function and you can achieve this by:

    const hours = 15;
    const minutes = 32;
    var date = moment("1946-05-21").set("hour", hours).set("minute", minutes);
    

    or as a combined function

    var date = moment("1946-05-21").set({"hour": 15, "minute": 32});
    

    Note: the set function requires the value to be Integer type

提交回复
热议问题