无效日期-JavaScript GMT时间

问题描述 投票:0回答:1

我尝试仅在特定时间在我的网站上运行弹出窗口。所以我做了这段代码,但在控制台“ Invalid Date”中出错。我需要将弹出窗口设置为伦敦时间。有什么问题吗?

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);
});
javascript jquery time gmt
1个回答
0
投票
var date = new Date().toLocaleString("en-GB", {timeZone: "Europe/London"});
date = new Date(date); // Invalid Date since date is like  "13/01/2020, 02:36:57"

新日期将采用YYYY-MM-DDYYYY-MM-DDTHH:MM:SSZ格式的字符串

尝试更改字符串格式并尝试。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.