我正在构建一个轮播,显示特定于周五晚上的特色内容。您可以在下面看到加载时我使用 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);
您可以使用它来创建包含当前年/月/日组合和所需小时/分钟组合的日期。
关于javascript - Jquery当前日期小于X,在特定时间更改(而不是午夜),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31481086/