计算到下一个小时的时间量 [英] Calculate amount of time until the next hour

查看:67
本文介绍了计算到下一个小时的时间量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个公共汽车网站项目,公共汽车每小时运行一次。我在创建一个从现在到下一个小时之间找到时间的小部件时遇到了麻烦,因此很明显下一个总线何时运行。我的客户端要求它是在javascript中。有什么建议?
提前致谢。

I'm working on a busing website project and the buses run every hour. I'm having trouble creating a widget that finds the time between now and the next hour, so that it is clear when the next bus will run. My client requires that it is in javascript. Any suggestions? Thanks in advance.

推荐答案

function getMinutesUntilNextHour() { return 60 - new Date().getMinutes(); }

请注意,系统时钟关闭的人将错过他们的总线。在客户端的计算机上使用服务器时间而不是时间可能更好(AKA至少部分是非客户端javascript解决方案)。

Note that people who's system clocks are off will miss their bus. It might be better to use the server time instead of the time on the client's computer (AKA at least partly a non-client-side-javascript solution).

这篇关于计算到下一个小时的时间量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆