如何获得 moment.js 的两个日期时间之间的差异?

How to get difference between two datetime of moment.js?

如何计算 moment.js 中两个日期时间的差异?

moment.duration((moment(startDate).format("MM-DD-YYYY h:mm:ss a")).diff(moment(new Date()).format("MM-DD-YYYY h:mm:ss a")));

and My startDate = 2022-02-02T12:12:25Z

我找到了解决方案,可能会帮助其他人:

var now = moment(new Date(), "DD/MM/YYYY HH:mm:ss");
var then = moment(new Date(startDate), "DD/MM/YYYY HH:mm:ss");
var diffTime = moment.duration(then.diff(now));   
and it depends  to you how you want to get difference in seconds ,minutes  or hours :
diffTime.asHours();