最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I subtract hours and minutes from a HH:MM time string? - Stack Overflow

programmeradmin9浏览0评论

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

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

Share Improve this question asked Feb 7, 2016 at 18:20 Er KK ChopraEr KK Chopra 1,8508 gold badges33 silver badges57 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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();
发布评论

评论列表(0)

  1. 暂无评论