尝试使用来自php的UNIX时间戳的jQuery Countdown [英] Trying to use jQuery Countdown with UNIX timestamp from php

查看:104
本文介绍了尝试使用来自php的UNIX时间戳的jQuery Countdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我正面临一个问题,显示正确的剩余时间到结束日期。

As the title says I'm facing a problem displaying the right left time to an end date.

我正在使用这个jquery插件: http://keith-wood.name/countdown.html

I'm using this jquery plugin: http://keith-wood.name/countdown.html

假设我们的时间戳是由这样的PHP脚本生成的: $ end_date = strtotime($ row4 ['end']); // 2012-05-09 06:00:00成为1336536000

Let's assume that our timestamp is generated by a PHP script like this: $end_date = strtotime($row4['end']); // 2012-05-09 06:00:00 becomes 1336536000

我用这个( $ i

$('.count-<?php echo $i; ?>').countdown({until: new Date(<?php echo $end_date; ?> * 1000), layout: '{dn} days {hnn} hrs {mnn} min {snn} sec', compact: true});

现在是06:21 AM。而不是预期的1天剩余结果,我得到1天17小时04分21秒。

Right now it's 06:21 AM here. Instead of the expected 1 day left result I get "1 days 17 hrs 04 min 21 sec".

我在这里缺少什么?

推荐答案

我一直在使用API​​已经有一段时间了,但我似乎无法弄清楚你的代码是什么。也许(但也许只是)你使用直到属性是错误的。

I have been using the API for quite a while now, but I cann't seem to figure out what's up with your code. Perhaps (but just perhaps) you're using the untill property wrong.

我通常使用的代码:

$(function(){
    var countdown = $('#countdown'),
        ts = new Date(<?php echo $date_to * 1000; ?>),
        finished = true;

    if((new Date()) > ts)
    {
        finished = false;
    }

    $('#cool-countdown').countdown({
        timestamp   : ts,
        callback    : function(days, hours, minutes, seconds)
        {
            var message = "";

            message += days + " days, ";
            message += hours + " hours, ";
            message += minutes + " minutes, ";
            message += seconds + " seconds ";

            message = (finished ? "Countdown finished" : "left untill the New Year");

            countdown.html(message);
        }
    });

});

显然你应该将它扩展为feature singular。

Obviously you should extend this to feature singular.

这篇关于尝试使用来自php的UNIX时间戳的jQuery Countdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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