How to make operations with Dates/Hours in Javascript?

前端 未结 3 1271
小鲜肉
小鲜肉 2021-01-28 14:03

I have to subtract two hours passed by the user in the format \'HH: MM\' and the result has to divide by the number of feeds on the day and set the exact hours that it should fe

3条回答
  •  隐瞒了意图╮
    2021-01-28 14:29

    If you prefer to use a library, you can use momentJS => https://momentjs.com/docs/

    But I dont think you need to.

    If you want to subtract two hours from a certain date you can do it like this /

    var x = new Date();
    x = Date.parse(x);
    x = x - 7200000;
    x = new Date(x);
    
    console.log(x);
    

提交回复
热议问题