简体   繁体   English

Moment.js如何显示一天中的剩余时间(带时区偏移)

[英]Moment.js How to display time remaining in day (with timezone offset)

How to display time remaining until midnight, like this: 22 hours 48 minutes 12 seconds remaining 如何显示直到午夜的剩余时间,像这样:剩余22小时48分钟12秒

To make things a bit more difficult, this should show in the UTC+2 timezone. 为了使事情变得更加困难,这应该在UTC + 2时区中显示。 Is this possible in plain javascript or easier with momentjs? 是否可以使用普通javascript或使用momentjs轻松实现? Any help appreciated! 任何帮助表示赞赏!

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM