【发布时间】:2020-04-29 18:33:09
【问题描述】:
我尝试仅在特定时间在我的网站上运行弹出窗口。所以我编写了这段代码,但在控制台“无效日期”中出现错误。我需要将弹出窗口设置为伦敦时间。有什么问题?
jQuery(document).ready(function($){
var date = new Date().toLocaleString("en-GB", {timeZone: "Europe/London"});
date = new Date(date);
var curHr = date.getHours();
var minutes = 1;
if ((curHr > 16 && curHr < 24) || (curHr > 0 && curHr < 8)) {
date.setTime(date.getTime() + (minutes * 60 * 1000));
var active = Cookies.get('active');
if (active == 'yes') {
return false; // cookie active do nothing
} else { //trigger popup and set a cookie
setTimeout(function() {
$(".fancybox").eq(0).trigger('click');
}, 500);
$(".fancybox")
.attr('rel', 'group')
.fancybox({
padding: 0,
width: 530,
height: 550,
scrolling: 'auto'
});
}
Cookies.set('active', 'yes', {
expires: 1 / 1440 // set to 1 minute.
});
}
console.log(date);
});
【问题讨论】:
-
删除日期 = 新日期(日期);
-
这会返回错误:“Uncaught TypeError: date.getHours is not a function”
标签: javascript jquery time gmt