javascript - 在 JavaScript 计数器中使用主机日期

标签 javascript php jquery date

我正在我的网站中使用此脚本进行倒计时,它可以工作

<script type="text/javascript">

 (function (e) {
e.fn.countdown = function (t, n) {
function i() {
    eventDate = Date.parse(r.date) / 1e3;
    currentDate = Math.floor(e.now() / 1e3);
    if (eventDate <= currentDate) {
        n.call(this);
        clearInterval(interval)
    }
    seconds = eventDate - currentDate;
    days = Math.floor(seconds / 86400);
    seconds -= days * 60 * 60 * 24;
    hours = Math.floor(seconds / 3600);
    seconds -= hours * 60 * 60;
    minutes = Math.floor(seconds / 60);
    seconds -= minutes * 60;
    days == 1 ? thisEl.find(".timeRefDays").text("day") : thisEl.find(".timeRefDays").text("day");
    hours == 1 ? thisEl.find(".timeRefHours").text("hours") : thisEl.find(".timeRefHours").text("hours");
    minutes == 1 ? thisEl.find(".timeRefMinutes").text("Minutes") : thisEl.find(".timeRefMinutes").text("Minutes");
    seconds == 1 ? thisEl.find(".timeRefSeconds").text("Seconds") : thisEl.find(".timeRefSeconds").text("Seconds");
    if (r["format"] == "on") {
        days = String(days).length >= 2 ? days : "0" + days;
        hours = String(hours).length >= 2 ? hours : "0" + hours;
        minutes = String(minutes).length >= 2 ? minutes : "0" + minutes;
        seconds = String(seconds).length >= 2 ? seconds : "0" + seconds
    }
    if (!isNaN(eventDate)) {
        thisEl.find(".days").text(days);
        thisEl.find(".hours").text(hours);
        thisEl.find(".minutes").text(minutes);
        thisEl.find(".seconds").text(seconds)
    } else {
        alert("Invalid date. Example: 30 Tuesday 2013 15:50:00");
        clearInterval(interval)
    }
}
thisEl = e(this);
var r = {
    date: null,
    format: null
};
t && e.extend(r, t);
i();
interval = setInterval(i, 1e3)
}
})(jQuery);
$(document).ready(function () {
function e() {
    var e = new Date;
    e.setDate(e.getDate() + 60);
    dd = e.getDate();
    mm = e.getMonth() + 1;
    y = e.getFullYear();
    futureFormattedDate = mm + "/" + dd + "/" + y;
    return futureFormattedDate
}
$("#countdown").countdown({
    date: "<?php echo $newcounter ?> ", // Change this to your desired date to countdown to
    format: "on"
});
     });

          </script> 

但我有一个问题。该脚本使用我的用户计算机日期,但我想使用我的网站主机日期。如何更改从主机读取的日期? 谢谢。

最佳答案

很确定这会起作用:

currentDate = <?php echo time() ?>;

看起来 currentDate 只是 time() 将为您提供的 Unix 时间戳。

关于javascript - 在 JavaScript 计数器中使用主机日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24554523/

相关文章:

javascript - 为什么 jQuery 在循环时返回 span 元素内容的每个字符?

javascript - 如何顺序处理来自 API 的异步结果?

javascript - 响应式导航栏 - 不会在 Drupal 上正确和时髦地折叠

php - Mysql错误093

php - 根据比较更改返回字段(MySQL)

javascript - 将逗号分隔值放入输入字段

php - 单击按钮时转到下一页并刷新上一页 Jquery Mobile

javascript - 如何检查,所选文本是否为粗体(contenteditable)

javascript - 需要帮助修改 javascript 片段

php - 数据库输出的翻译