Sluggo
Sluggo

Reputation: 617

Make FlipClock.js count up from set date

I'm using Justin Kimbrell FlipClock.js (from flipclockjs.com) like this:

$(function(){
    FlipClock.Lang.Custom = { days:'Dagar', hours:'Timmar', minutes:'Minuter', seconds:'Sekunder' };
    var opts = {
        clockFace: 'DailyCounter',
        countdown: true,
        language: 'Custom'
    };
    var countdown = 1475924400 - ((new Date().getTime())/1000); // from: 10/08/2016 12:00 pm +0100
    countdown = Math.max(1, countdown);
    $('.clock-builder-output').FlipClock(countdown, opts);
});

And it seems to be working well. But I'd like to add another counter that works the same way, but that counts UP from a set date and time in the past. Can anyone please help me with this?

Upvotes: 0

Views: 1631

Answers (1)

Sluggo
Sluggo

Reputation: 617

Solved it myself. -By using FlipClock().setTime() and sending in the time elapsed in seconds since the clock should have been 00:00:00 (starting time). Like this:

FlipClock.Lang.Custom = { days:'Dagar', hours:'Tim', minutes:'Min', seconds:'Sek' };

var startDate = new Date('Fri Jan 8 2016 12:00:00 GMT+0200'); //What date to start counting from
var now = Math.floor(Date.now()/1000); //Current timestamp in seconds
var clockStart = now - startDate.getTime()/1000; //What to set the clock at when page loads

var clock2 = $('.clock2').FlipClock(opts).setTime(clockStart); //Start clock

Upvotes: 2

Related Questions