.diff不是moment.js的函数 [英] .diff is not a function on moments.js
本文介绍了.diff不是moment.js的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 moment.js 做一个小脚本,它显示了多少小时和分钟(单独分开) )我有一个特定的小时。
I try to do a little script using moment.js, that shows me how many hours and minutes (seperate) I have until a specific hour.
var TimeA = moment('08:00:00', 'HH:mm:ss').format('HH:mm:ss');
var TimeB = moment('16:00:00', 'HH:mm:ss').format('HH:mm:ss');
var DiffAB = TimeA.diff(TimeB);
var DiffHours = DiffAB.format('H');
var DiffMinutes = DiffAB.format('mm');
console.log('TimeA: ' + TimeA);
console.log('TimeB: ' + TimeB);
console.log('Difference A-B: ' + DiffAB);
console.log('Diff Hours: ' + DiffHours);
console.log('Diff Minutes: ' + DiffMinutes);
这就是我到目前为止所尝试的内容。但是我收到以下错误:
Thats what I've tried so far. But I get the following error:
TimeA.diff is not a function
我不确定我在这里做错了什么。
I am not sure what I am doing wrong here.
推荐答案
当你调用 .format()
时,你得到的是一个字符串。你不再处理片刻物体了。
When you call .format()
, what you get back is a String. You're no longer dealing with a moment object.
这篇关于.diff不是moment.js的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文