Add hours with the Final Countdown plugin

2

I'm doing a countdown system and I'm using "The Final Countdown jQuery"

$('#clock').countdown('2015/02/16', function(event) {
    $(this).html(event.strftime('%D dias %H:%M:%S'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="http://mindvelopers.com/jquery.countdown.min.js"></script>

<div id="clock"></div>

My problem is that I need to add +21 hours to each event (to the result), but I can not add it the way this function is done.

    
asked by anonymous 15.02.2015 / 04:51

2 answers

3

To add hours to the result you can use new Date .

You can directly use new Date() in the first parameter of countdown with a format that is recognized by Date.parse as ISO 8601 , read at link .

But if you want to keep the string format to facilitate without having to pass a more complex parameter (like ISO for example) then you can use its string combined with split and new Date(ano, mês[, dia[, hora[, minutos[, segundos[, milesegundos]]]]]); :

    var endIn = '2015/02/16';
    var sumHours = 21;//Soma 21 horas

    var endInV = endIn.split("/");
    var withSum = new Date(endInV[0], endInV[1] - 1, endInV[2]);
    withSum.setHours(withSum.getHours() + sumHours);

    $('#clock').countdown(withSum, function(event) {
        $(this).html(event.strftime('%D dias %H:%M:%S'));
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="http://mindvelopers.com/jquery.countdown.min.js"></script>

<div id="clock"></div>
    
15.02.2015 / 05:49
1

It can also be done like this:

var data1 = new Date ('2015/02/16');
var data2 = new Date (data1);
var addHoras = 21;
data2.setHours ( data1.getHours() + addHoras);

$('#clock').countdown(data2, function(event) {
    $(this).html(event.strftime('%D dias %H:%M:%S'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="http://mindvelopers.com/jquery.countdown.min.js"></script>

<div id="clock"></div>

Fiddle

Example that follows the format of the ISO 8601 :

var data1 = new Date ('2015-02-16T02:00:00.000Z');
var data2 = new Date (data1);
var addHoras = 21;
data2.setHours ( data1.getHours() + addHoras);

$('#clock').countdown(data2, function(event) {
    $(this).html(event.strftime('%D dias %H:%M:%S'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="http://mindvelopers.com/jquery.countdown.min.js"></script>

<div id="clock"></div>

Fiddle

    
15.02.2015 / 17:45