Answer the question
In order to leave comments, you need to log in
How to fix the script? How to count down days from UNIX time?
Hello!
On the Internet, I found a script that timestamp converts how many minutes, hours ago the material was added. The problem is that he doesn't count the days. I twist it this way and that for a day now, nothing happens, there is not enough knowledge in JS to understand.
Maybe someone has already encountered this and will help to add or rebuild the script so that it counts how many seconds, minutes, hours, and then days ago the material was added?
Thank you!<span id="add_time"></span>
<script type="text/javascript">
function corrDate(t, n) {
return n != 0 ? " " + n + " " + t[n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] + ", " : "";
};
(function(time) {
var everySecond = true,
ar = arguments,
_ = Math.ceil((time - (1552846855 * 1000)) / (1000)),
day, hour, min, sec, text = [
['день', 'дня', 'дней'],
['час', 'часа', 'часов'],
['минуту', 'минуты', 'минут'],
['секунду', 'секунды', 'секунд']
],
res;
day = Math.floor((_ / 86400));
_ = _ - (day * 86400);
hour = Math.floor((_ / 3600));
_ = _ - (hour * 3600);
min = Math.floor((_ / 60));
_ = _ - (min * 60);
if (min > 0) {
if (min == 1) {
res = '1 минуту назад'
} else {
if (hour > 0) {
if (hour == '1') {
res = '1 час назад'
} else {
res = corrDate(text[1], hour)
}
} else {
res = corrDate(text[2], min)
}
}
} else {
res = 'Меньше минуты назад'
}
document.getElementById("add_time").innerHTML = res.replace(/\,\s$/, " назад");
if (everySecond) {
setTimeout(function() {
ar.callee(new Date().getTime());
}, 1000);
}
})(new Date().getTime());
</script>
Answer the question
In order to leave comments, you need to log in
This is an old script for Ucoz sites.
In the condition, there is no checking of days,
respectively, in the corrDate() function and an array of declensions of names ['day', 'days', 'days'] is not passed anywhere, something like this res = corrDate(text[0], day)
To make it all work, most likely you need to add the condition how many days have passed since the date and hours if they are zero, then count minutes and seconds, if not, then hours and days
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question