Jquery 当前日期小于 X,在特定时间更改(而不是午夜)
Jquery Current Date Less Than X, Change At Specific Time (Instead of Midnight)
我正在构建一个显示特定于周五晚上的特色内容的轮播。您可以在下面看到加载时我使用 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(),而不是特定的一天?
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);
您可以使用它来创建具有当前 year/month/day 组合和所需 hours/minutes 组合的日期。
我正在构建一个显示特定于周五晚上的特色内容的轮播。您可以在下面看到加载时我使用 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(),而不是特定的一天?
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);
您可以使用它来创建具有当前 year/month/day 组合和所需 hours/minutes 组合的日期。