Pregunta:
Fecha: 24-10-2015 12:08:20
(En Español)
tengo un script que hace una cuenta regresiva pero cuando es un numero solo me aparece así "1" pero quiero que aparezca así "01" esto se hace desde las lineas 21, 22 , 23 y 24 pero no he podido lo he intentado con ">= 9", "!>=" y "> 9".
Ayuda con cuenta regresiva[Resuelta]
Hola amigos,tengo un script que hace una cuenta regresiva pero cuando es un numero solo me aparece así "1" pero quiero que aparezca así "01" esto se hace desde las lineas 21, 22 , 23 y 24 pero no he podido lo he intentado con ">= 9", "!>=" y "> 9".
function setTime() {
var time = 1453507200 * 1000;
var today = new Date();
var diff = time - today.getTime();
var total = diff / (24 * 60 * 60 * 1000);
var aux = 0;
if (true && Math.abs(total) > 365) {
var years = parseInt(total / 365);
var text_years = Math.abs(years) != 1 ? years + ' años ' : years + ' año ';
aux = total / 365;
var days = parseInt((aux - years) * 360);
total = (aux - years) * 365;
} else {
var text_years = '';
var days = parseInt(total);
}
var hours = parseInt((total - parseInt(total)) * 24);
aux = (total - parseInt(total)) * 24;
var minutes = parseInt((aux - hours) * 60);
aux = (aux - hours) * 60;
var seconds = parseInt((aux - minutes) * 60);
var text_days = Math.abs(days) != 1 ? days : days;
var text_hours = Math.abs(hours) != 1 ? zerofill(hours) : zerofill(hours);
var text_minutes = Math.abs(minutes) > 9 ? zerofill(minutes) : '0' + zerofill(minutos);
var text_seconds = Math.abs(seconds) > 9 ? zerofill(seconds) : '0' + zerofill(seconds);
var message = text_years + text_days + text_hours + text_minutes + text_seconds;
if (diff < 0) {
message = message.replace(/-/g, '');
}
//jQuery('#strdate').html(message);
jQuery('#dias_reloj').html(text_days);
jQuery('#horas_reloj').html(text_hours);
jQuery('#minutos_reloj').html(text_minutes);
jQuery('#segundos_reloj').html(text_seconds);
}
function zerofill(num) {
//return (Math.abs(num) < 10 && Math.abs(num) > 0) ? '0' + num : num;
return num;
}
setInterval(function() {
setTime();
}, 1000);
Votos: 0 -
Respuestas: 1 -
Vistas: 13
Compartir en: Google
Facebook
Twitter
LinkedIn
Link
Respuestas:
-
Fecha: 25-10-2015 09:12:52 Hola,
Checa este link.
En pocas palabras crea una función:
String.prototype.lpad = function(padString, length) { var str = this; while (str.length < length) str = padString + str; return str; }
y luego la llamas:
var str = "5"; alert(str.lpad("0", 4)); //result "0005" var str = "10"; // note this is string type alert(str.lpad("0", 4)); //result "0010"Votos: 4 - Link respuesta
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
