Charles Marsh
Charles Marsh

Reputation: 465

Jquery Daily Timer

I'm trying to find a jQuery timer that will countdown to 10am everyday, monday to friday. On friday it will countdown to 10am monday.

I've tried KK Countdown but it seems a little difficult to modify.

The timezone will be set to one specific zone, as its a local website only.

Any Ideas anyone? I can only use javascript no PHP unfortunately as the website is a hosted e-commerce solution.

Upvotes: 0

Views: 2143

Answers (2)

Baldur
Baldur

Reputation: 441

Depending on the complexity of your requirements it can sometimes be exciting to reinvent the wheel. I think you can accomplish yours in just a few lines ... but then again there might be stuff I am not thinking of.

    // 24 hour based
    var targetHour = 10;

    var currentTime = new Date();

    // sun 0 mon 1 ... fri 5 sat 6
    var currentDay = currentTime.getDay();

    var offset = 24;
                    // friday
    if (currentDay === 5) {
        offset = 60;
    }              // saturday
    else if(currentDay === 6) {                                                                   
        offset = 48;
    }

    if(currentTime.getHours() > targetHour) {
        console.log('hours:', (targetHour + offset) - currentTime.getHours() - 1);
        console.log('minutes:', 60 - currentTime.getMinutes());
    } 
    else if(currentTime.getHours() < targetHour) {
        console.log(targetHour - currentTime.getHours() - 1);
        console.log('minutes:', 60 - currentTime.getMinutes());
    }

Upvotes: 2

ipr101
ipr101

Reputation: 24236

There's a list of jQuery countdown timers here -

http://www.tripwiremagazine.com/2011/04/9-cool-jquery-countdown-scripts.html

Upvotes: 1

Related Questions