Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I subtract hours and minutes from a HH:MM time string?

I have a string realTime = 10:15 and i have subtract 1:20 means(one hours twenty minutes) from string realTime .

output should be = 8:55.

I am trying something with moment

moment().subtract(realTime , '1:20');

But it's not working, Help me to find the solution. Thanks

like image 991
Er KK Chopra Avatar asked Oct 24 '25 00:10

Er KK Chopra


1 Answers

It's

moment(realTime, 'HH:mm').subtract(80, 'minutes');

Or, alternatively, you can use moment.duration

var realTime = '10:15';
var duration = moment.duration({hours: 1, minutes: 20})
var sub = moment(realTime, 'HH:mm').subtract(duration).format();
like image 173
baao Avatar answered Oct 26 '25 15:10

baao