Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
How to convert jquery countdown function to countup function?

I am working on a portal which is basically using a jquery plugin called countdown i.e. https://github.com/hilios/jQuery.countdown

The piece of code is:

$(document).ready(function(){

$("#countdown").countdown("2022/06/25 10:00:00", function(event) {
  var $this = $(this).html(event.strftime(''
     + '%-D Days'
});

How can I make it in reverse? Instead of counting it down to the date, is it possible to count from the date? and display how many days it's been.

Any help would be highly appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As you have not posted the complete countdown function, I am assuming the one from the link you have pasted (https://github.com/hilios/jQuery.countdown)

If you carefully look at the countdown function here https://github.com/hilios/jQuery.countdown/blob/223789964fd1854e04a60d6eba3fd22d20b1f34f/src/countdown.js#L269 you can easily modify it.

I have had similar requirements in the past and writing my own function was easier than modifying the existing one.

For example, the function:

$(document).ready(function () {
    $(function () {
      var calcNewYear = setInterval(function () {
        var date_started = new Date("2022/06/25"); // your date to count from
        var date_now = new Date(); // current timestamp 
        var one_day = 1000 * 60 * 60 * 24;
        var days = Math.floor((date_now - (date_started)) / one_day); // days from the date
        }
    }
}

Then include it wherever it is needed:

("#countdown").html(days + ' Days');
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda