Reputation: 407
Trying to use moment's diff function to calculate ms difference in time b/w one moment that will always have a constant timezone and another timezone indifferent moment. I'm using moment-timezone to help with this.
Here's my example code:
const parisTime = moment({hour:18, minutes:0}).tz('Europe/Paris');
const currentTime = moment(); //right now
const difference = moment.duration(parisTime.diff(currentTime))
When I perform this operation diff treats currentTime as the same timezone as Europe/Paris which won't work b/c currentTime could be from anywhere in the world.
Any ideas how to resolve this ? Your help is much appreciated - correct answer will be marked as so.
Thank you!
Upvotes: 0
Views: 1643
Reputation: 2452
I think you want to compute the difference between today at 18:00 Paris time and now. That would be
moment.tz('18:00', 'HH:mm', 'Europe/Paris').diff(moment());
Basically, you need to parse 18:00 as Paris time. What is happening right now is that you are parsing it as local time, and then converting that to Paris time.
Note that because you aren't specifying a date, the day is assumed to be 'today', meaning that this code can result in both positive and negative values.
See this blog post for more information about how moment's constructor functions work.
Upvotes: 3