I am currently working on a project that involves time calculations.
const currentCETTime = moment.tz('2020-03-18 15:58:38', 'Europe/Madrid');
const limitCETTime = moment.tz('2020-03-18 18:00:00', 'Europe/Madrid');
console.log('current',currentCETTime.format('HH:mm:ss'));
console.log('limit', limitCETTime.format('HH:mm:ss'));
const seconds = Math.abs(limitCETTime.diff(currentCETTime) / 1000);
console.log('hours', (seconds / 60) / 60);
const rem = moment(seconds * 1000);
console.log('diff', moment(rem).tz('Europe/Madrid').format('HH:mm'));
<script src="https://momentjs.com/downloads/moment.min.js"></script>
<script src="https://momentjs.com/downloads/moment-timezone-with-data-10-year-range.min.js"></script>
Unfortunately, I have encountered an issue with the time difference calculation:
https://i.sstatic.net/nJNBW.png
The expected result is a difference of 2:01 hours instead of displaying as 03:01.