如何将时区添加到jQuery倒计时

时间:2013-08-09 20:59:25

标签: jquery html timezone countdown

我正在使用我发现的倒计时,这将倒计时开始直播,所以它目前正在倒数到PC的时间,而我希望它倒计时到BST(8月25日@9am)(英国)时间)。

以下是HTML代码,我相信这就是您所需要的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="ie.css" type="text/css" charset="utf-8" />
    <script language="Javascript" type="text/javascript" src="js/jquery-1.4.4.js"></script>
    <script language="Javascript" type="text/javascript" src="js/jquery.lwtCountdown-1.0.js"></script>
    <script language="Javascript" type="text/javascript" src="js/misc.js"></script>
</head>
<body>
    <div id="countdown">
        <div class="dash weeks_dash">
            <span class="dash_title">weeks</span>
            <div class="digit">0</div>
            <div class="digit">0</div>
        </div>
        <div class="dash days_dash">
            <span class="dash_title">days</span>
            <div class="digit">0</div>
            <div class="digit">0</div>
        </div>
        <div class="dash hours_dash">
            <span class="dash_title">hours</span>
            <div class="digit">0</div>
            <div class="digit">0</div>
        </div>
        <div class="dash minutes_dash">
            <span class="dash_title">minutes</span>
            <div class="digit">0</div>
            <div class="digit">0</div>
        </div>
        <div class="dash seconds_dash">
            <span class="dash_title">seconds</span>
            <div class="digit">0</div>
            <div class="digit">0</div>
        </div>
    </div> <!-- end of countdown -->
    <!-- start of the javascript code that handles the countdown -->
    <script language="javascript" type="text/javascript">
        jQuery(document).ready(function() {
            $('#countdown').countDown({
                targetDate: {
                    'day':      25,
                    'month':    8,
                    'year':     2013,
                    'hour':     9,
                    'min':      0,
                    'sec':      0
                }
            });
        });
    </script>
    <!-- end of the javascript code that handles the countdown -->
</body>

1 个答案:

答案 0 :(得分:0)

我认为你的意思是this component。下次,请提供一个链接,以便我们不必搜索。

首先确定您的活动的UTC时间。有许多方法可以做到这一点,所以我不会在这里解决它们,除非这是你的问题。

您提供的示例的UTC时间是2013-08-05 8:00:00。

在他们的文档here中,他们展示了如何在UTC中传递时间:

jQuery(document).ready(function() {
    $('#countdown').countDown({
        targetDate: {
            'day':      25,
            'month':    8,
            'year':     2013,
            'hour':     8,        // note the input time is in utc
            'min':      0,
            'sec':      0,
            'utc':      true      // set this parameter to true
            }
        });
    });

jquery.lwtCountdown-1.0.js中挖掘组件本身的来源,此代码中存在错误:

if (options.targetDate)
{
    targetTime = new Date(options.targetDate.month + '/' + options.targetDate.day + '/' + options.targetDate.year + ' ' + options.targetDate.hour + ':' + options.targetDate.min + ':' + options.targetDate.sec + (options.targetDate.utc ? ' UTC' : ''));
}

他们通过组合以mm / dd / yyyy格式硬编码的日期字符串来创建Date。这在使用其他日期格式的地方不起作用,例如英国使用的dd / mm / yyyy格式。他们应该传递单独的参数。将该代码更改为:

if (options.targetDate)
{
  var td = options.targetDate;
  if (options.targetDate.utc)
    targetTime = new Date(Date.UTC(td.year, td.month-1, td.day, td.hour, td.min, td.sec));
  else
    targetTime = new Date(td.year, td.month-1, td.day, td.hour, td.min, td.sec);
}

您还应该将此错误报告给作者。

相关问题