currentTime是否在18:00到2:00之间 [英] Does currentTime fall between 18:00 and 2:00

查看:91
本文介绍了currentTime是否在18:00到2:00之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态打开和关闭时间的条形时间表,我必须计算当前时间是否在今天的开放时间内。

I have a bar timetable with dynamic open and closing times and I have to calculate if currentTime falls within today's opening hours.

问题是开放和关闭时间不是在同一天。如何计算currentTime是否在多天的特定时间范围内?

The problem is the open and closing times aren't in the same day. How does one calculate if currentTime falls within a range of specific times across multiple days?

我在这个项目中使用jquery。

I'm using jquery on this project.

推荐答案

你可以使用javascripts日期对象来计算这个:

You can calculate this using javascripts Date Object like :

var start = new Date(2012,6,20,13).getTime();
var now = new Date().getTime();
var end = new Date(2012,6,21,2).getTime();

if( (start < now ) && (now < end )) {
  console.log("opened");
}
else {
 console.log("closed");
}

将输出开到明天凌晨2点,然后输出将关闭。

would output opened until tomorrow 2am then it will output closed.

您可以查看此 JSBin示例并更改开始时间看看它是如何变化的

you can look at this JSBin Example and change the start time to see how it changes

这篇关于currentTime是否在18:00到2:00之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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