无效日期 - JavaScript GMT 时间

Invalid Date - JavaScript GMT time

我尝试仅在特定时间 运行 在我的网站上弹出 window。所以我编写了这段代码,但在控制台 "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);
});
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 格式的字符串(ISO 中的示例格式)

尝试改变String格式试试

var date = new Date().toLocaleString("en-GB", {timeZone: "Europe/London"});
date = new Date(date); // Not working

var date = new Date().toLocaleString("en-US", {timeZone: "Europe/London"});
date = new Date(date); // Working

var date = new Date().toLocaleString("en-UK", {timeZone: "Europe/London"});
date = new Date(date); // Working