特定时间和日期的Javascript倒计时 [英] Javascript countdown for specific time and date

查看:109
本文介绍了特定时间和日期的Javascript倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery插件将倒数计时器放在我的网页中。目前控制计时器显示内容的代码是:

I am using a jQuery plugin to put the countdown timer in my webpage. Currently the code that controls what the timer displays is:

<script type="text/javascript">
    var clock = $('.clock').FlipClock(3600 * 24 * 3, {
        clockFace: 'DailyCounter',
        countdown: true
    });
</script>



插件的JS可以在这里查看: https://github.com/objectivehtml/FlipClock/blob/master/js/ flipclock / flipclock.js

这里可以看到正在使用的代码的示例页面:
http://flipclockjs.com/faces/daily-counter

The example page of the code in use can be seen here: http://flipclockjs.com/faces/daily-counter

目前计时器是3天的倒计时,每次刷新页面时都会重置。我想使用倒数计时器的自定义时间,这将是绝对的(不会通过页面刷新重置)。我希望日期是2013年9月30日太平洋标准时间中午12:00(美国西部 - 加利福尼亚时区)。

Currently the timer is a countdown for 3 days which resets everytime the page is refreshed. I want to use a custom time for the countdown timer which will be absolute(wont reset with page refresh). I want the date to be September 30, 2013 at 12:00pm PST (US West - California Time Zone).

无论如何使用Javascript或jQuery执行此操作?

Is there anyway to do this using Javascript or jQuery?

推荐答案

获取当前时间,并注意这将是用户计算机时钟上设置的时间,无论设置为何,设置特定日期,然后计算差异并将其用于插件:

Get the current time, and note that this will be the time set on the users computer clock, whatever that is set to, and set a certain date, then calculate the difference and use that for the plugin:

var date  = new Date(Date.UTC(2013, 8, 30, 12, 0, 0));
var now   = new Date();
var diff  = date.getTime()/1000 - now.getTime()/1000;

var clock = $('.clock').FlipClock(diff, {
    clockFace: 'DailyCounter',
    countdown: true
});

对于准确的时间,我会使用您的网络服务器重新输出当前时间。

For accurate times I would reccoment using your webserver to output the current time.

这篇关于特定时间和日期的Javascript倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆