问题描述
我正在构建一个轮播,该轮播显示特定于星期五晚上的特色内容。 在下面的内容中,您可以看到使用新的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;
}
});
}
有谁知道我该如何在新的Date()中传递时间,而不是特定的日期?
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);
您可以使用它来创建具有当前年/月/日组合和所需小时/分钟组合的日期。