我在我的网站上对此项目进行直播,用户可以在其中投票。
现在,投票将于本月31日深夜结束。为了安全起见,我不想删除任何代码,而是添加一些代码以将当前日期与上述日期进行比较。如果在9月1日00:00:01上,用户单击“投票”按钮,那么我想显示一条消息,说投票已关闭。
我目前正在使用Jquery对话框进行投票,因此我可以隐藏div内容并显示另一个div内容以投票关闭消息。
谁能帮忙。
谢谢
我正在尝试这种方式
var now = new Date();
var datetime = now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDay();
datetime += ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
OUTPUT is: Tue Aug 27 2013 17:08:47 GMT+0100 (GMT Daylight Time)
我不知道该如何与投票截止日期进行比较。
最佳答案
$(document).ready(function () {
eventTime = Date.parse('31 August 2013') / 1000;
function time_until() {
currentTime = Math.floor(jQuery.now() / 1000);
seconds = eventTime - currentTime;
days = Math.floor(seconds / (60 * 60 * 24));
$('#time').html('seconds ' + seconds + '<br/>days ' + days);
}
setInterval(time_until,1000)
});
为你的代码
function time_until() {
currentTime = Math.floor(jQuery.now() / 1000);
seconds = eventTime - currentTime;
if(second == 0){
//Stop voting
}
days = Math.floor(seconds / (60 * 60 * 24));
$('#time').html('seconds ' + seconds + '<br/>days ' + days);
}