Reputation: 53
How to display time remaining until midnight, like this: 22 hours 48 minutes 12 seconds remaining
To make things a bit more difficult, this should show in the UTC+2 timezone. Is this possible in plain javascript or easier with momentjs? Any help appreciated!
Upvotes: 1
Views: 4758
Reputation: 134
let now = moment();
let timeDiff = moment(now).utcOffset(120).endOf('day') - now;
let dur = moment.duration(timeDiff);
console.log(`${dur.hours()} hrs ${dur.minutes()} min ${dur.seconds()} sec until midnight.`);
<script src="https://momentjs.com/downloads/moment.min.js"></script>
Upvotes: 4