开发者

Jquery Countdown Server sync issue

I'm trying to create a co开发者_运维技巧untdown for an event. I'm using Jquery Countdown

I have this code:

$(function () {
    var fecha = new Date("July 30, 2011 00:00:00");
    $('#defaultCountdown').countdown({
        until: fecha,
        format: 'DHMS',
        expiryUrl: "http://www.google.com",
        serverSync: serverTime,
        timezone: -4
    });


});


function serverTime() {
    var time = null;
    $.ajax({
        url: 'serverTime.php',
        async: false,
        dataType: 'text',
        success: function (text) {
            time = new Date(text);
        },
        error: function (http, message, exc) {
            time = new Date();
        }
    });
    return time;
}

The script is working fine, but when I try to change the clock date, the countdown changes. Any idea why?


I imagine you created the serverTime.php file on your server? http://keith-wood.name/countdown.html Tab Timezones has the PHP code you'll need to add to serverTime.php for your script to use that. Also may want to fully qualify that to something like url: 'http:yourdomain.com/serverTime.php' But using that it should use your server time not your local PC time. If your server is on your local PC, then well... it would change.


I went to their site, with their example, and changing my system time affects their countdown as well. Their code relies on local system times.


What I see when you get the server time form the ajax call, it is not creating the JavaScript date object.

I searched and below worked for me.

// Split timestamp into [ Y, M, D, h, m, s ]
var t = "2010-06-09 13:12:01".split(/[- :]/);

// Apply each element to the Date function
var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);

alert(d);
// -> Wed Jun 09 2010 13:12:01 GMT+0100 (GMT Daylight Time) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜