我正在建立一个旋转木马,显示特定于周五晚上的特色内容。下面你可以看到加载我使用新的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(),但不是特定的一天?
答案 0 :(得分: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);
您可以使用它来创建包含当前年/月/日组合的日期以及所需的小时/分钟组合。