【问题标题】:Jquery Current Date Less Than X, Change At Specific Time (Instead of Midnight)Jquery 当前日期小于 X,在特定时间更改(而不是午夜)
【发布时间】:2015-07-17 17:03:40
【问题描述】:

我正在构建一个轮播,显示周五晚上的特色内容。下面你可以看到加载时我使用 new Date() 触发了对即将到来的周五晚上内容的点击。帐户当然希望在周五晚上 9 点而不是午夜活动结束后更改此内容。

function loadFirstMovie(){
        $el.find(settings.children).each(function(i){
            var t = $(this)
            var currentDate = new Date() // get current date
            var itemDate = new Date(t.attr('date'))

            if (currentDate < itemDate){
                t.trigger("click");
                return false;
            }
        });
    }

有谁知道我如何将时间传递给 new Date(),而不是特定的日期?

【问题讨论】:

    标签: javascript jquery date time


    【解决方案1】:
    var itemDate = new Date("2015-07-17T21:00:00");
    //Creates a Date specific to 17th of July 2015, 9:00PM UTC
    var year = 2015;
    var month = 7;
    var day = 17;
    var hours = 21;
    var minutes = 0;
    var seconds = 0;
    var milliseconds = 0;
    var alternativeItemDate = new Date(year, month, day, hours, minutes, seconds, milliseconds);
    

    您可以使用它来创建具有当前年/月/日组合和所需小时/分钟组合的日期。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多