JSFiddle - React, Tailwind, and code Playground

Mi contador

by Yolanda Robles

HTML

<div class="time">
</div>

JavaScript

(function ($) {

//**********************************
// Se le pasa un número de uno o más digitos.
// Si el número tiene un único dígito, lo devuelve
// con dos dítigos añadiéndole un 0 por delante.
//**********************************
function RellenarCeros(t) {
    t = t + "";
    if (t.length == 1)
        return "0" + t;
    else
        return t;
};


// ******************************************
// Función que convierte una fecha 
// de formato "05/11/2015 20:00:00"
// en un objeto fecha javascript
//********************************************
function ParseDate(strDate) {

    var res = strDate.split("/", 3);
    var dia = res[0];
    var mes = res[1];
    var stranyo = res[2].split(" ", 2);
    var anyo = stranyo[0];
    var strTiempo = stranyo[1].split(":", 3);
    var hh = strTiempo[0];
    var mm = strTiempo[1];
    var ss = strTiempo[2];

    // Los meses empiezan en el 0 es enero
    mes = mes - 1;

    return new Date(anyo, mes, dia, hh, mm, ss);

};

    // Método contador
    $.fn.countdown = function (valorInicial) {

        // variables
        var time = new Date();
        var interv;
        var divObj;

        // Establecemos una constante para el tiempo de actualización.
        var TiempoActualizacion = 1000;

            // Estamos inicializando el timer
            // si viene informado, lo inicializamos
            if (valorInicial !== undefined) {
                time = new Date(valorInicial);
            }

            // Función para mostrar el tiempo
            displayTime = function () {
                this.text(RellenarCeros(time.getHours() - 1) + ":" + RellenarCeros(time.getMinutes()) + ":" + RellenarCeros(time.getSeconds()));
            };

            // Función para empezar
            start = function () {

                this.interv = setInterval(function (obj) {
                    time = new Date(time - TiempoActualizacion);
                    if (time <= 0) {
                    
                   ...