如何显示剩余时间,直到午夜,这样的时刻: 22小时48分钟时间:12秒Moment.js如何显示剩余天(与时区偏移)
为了使事情更加困难,这应显示在UTC + 2时区。 这是可能的简单的JavaScript或更容易与momentjs? 任何帮助表示赞赏!
如何显示剩余时间,直到午夜,这样的时刻: 22小时48分钟时间:12秒Moment.js如何显示剩余天(与时区偏移)
为了使事情更加困难,这应显示在UTC + 2时区。 这是可能的简单的JavaScript或更容易与momentjs? 任何帮助表示赞赏!
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>
什么你试过这么远吗?请参阅[时间](http://momentjs.com/docs/#/durations/)。 – VincenzoC
总是使用时区库的东西。这里有一个[伟大的视频](https://youtu.be/-5wpm-gesOY),解释你为什么不应该自己处理时区。 –
@SumnerEvans据我所知moment.js是一个时区的东西和更多的图书馆;) – schrej