Javascript - 如何检查当前时间是否在两个不同时间之间

标签 javascript jquery jquery-mobile

<分区>

我正在尝试以编程方式检查我的 Web 应用程序的当前时间是否在两个预定义时间之间。我不知道如何获取当前时间,然后设置存储两个预定义时间的变量。伪代码看起来像这样

if(currentTime < shiftStart && currentTime <shiftEnd)
{
   shift = 2
}

但是我该如何声明和设置变量才能使代码正常工作。

最佳答案

var now = Date.now();
var time1 = //whatever time1 is
var time2 = //whatever time2 is

if (now > time1 && now < time2)
{
    alert("blah"):
}

关于Javascript - 如何检查当前时间是否在两个不同时间之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18132396/

相关文章:

javascript - 滚动到固定导航不粘

javascript - 从javascript中的查询字符串获取数据

javascript - jQuery UI 对话框确认

html - Jquery用html5数据属性隐藏和显示

javascript - jQuery Mobile - 使用 URL 参数打开可折叠集

javascript - 在转动滚轮之前,谷歌浏览器不会在某些网站上应用来自自建扩展的注入(inject)代码

jquery - jquery 中的可排序函数在停止时不执行追加

javascript - 使用ajax和jquery发送id

jquery-mobile - JQuery Mobile 可折叠内容

html - 如何在 CSS 中将左侧 float 元素居中用于手机 View ?