subtract time from date - moment js

前端 未结 6 1846
无人共我
无人共我 2020-12-03 03:04

I have for instance this datetime:

01:20:00 06-26-2014

and I want to subtract a time like this:

00:03:15

6条回答
  •  忘掉有多难
    2020-12-03 03:22

    Michael Richardson's solution is great. If you would like to subtract dates (because Google will point you here if you search for it), you could also say:

    var date1 = moment( "2014-06-07 00:03:00" );
    var date2 = moment( "2014-06-07 09:22:00" );
    
    differenceInMs = date2.diff(date1); // diff yields milliseconds
    duration = moment.duration(differenceInMs); // moment.duration accepts ms
    differenceInMinutes = duration.asMinutes(); // if you would like to have the output 559
    

提交回复
热议问题