Код
<script language="JavaScript" type="text/javascript">
jQuery.fn.timeUpdate = function (filter,pole,intarval, options) {
var options = jQuery.extend({
lang: {
years: ['год', 'года', 'лет'],
months: ['месяц', 'месяца', 'месяцев'],
days: ['день', 'дня', 'дней'],
hours: ['час', 'часа', 'часов'],
minutes: ['минута', 'минуты', 'минут'],
seconds: ['секунда', 'секунды', 'секунд'],
plurar: function(n) {
return (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); }
},
end: " назад",
tolkochto:"только что"
}, options);
var timeDifference = function(end, begin) {
if (end < begin) return false;
var difference = {
seconds: [end.getSeconds() - begin.getSeconds(), 60],
minutes: [end.getMinutes() - begin.getMinutes(), 60],
hours: [end.getHours() - begin.getHours() , 24],
days: [end.getDate() - begin.getDate() , new Date(begin.getYear(), begin.getMonth() + 1, 0).getDate()],
months: [end.getMonth() - begin.getMonth() , 12],
years: [end.getYear() - begin.getYear() , 0]
};
if(difference.years[0]!= 0 ){
delete (difference.days);
delete (difference.hours);
delete (difference.minutes);
delete (difference.seconds); }
else if(difference.months[0]!=0){
delete (difference.hours);
delete (difference.minutes);
delete (difference.seconds); }
else if(difference.days[0]!=0 ){
delete (difference.minutes);
delete (difference.seconds); }
else if(difference.hours[0]!=0 )
delete (difference.seconds);
var result = new Array();
var flag = false;
for (i in difference) {
if (flag) {
difference[i][0]--;
flag = false;
}
if (difference[i][0] < 0) {
flag = true;
difference[i][0] += difference[i][1];
}
if (!difference[i][0]) continue;
result.push(difference[i][0] + ' ' + options.lang[i][options.lang.plurar(difference[i][0])]);
}
return result.reverse().join(' ');
};
var timeUpdate = function () {
var need_to_time_update=$(filter);
if(need_to_time_update.size()>0){
need_to_time_update.each(function(i){
var date=need_to_time_update.eq(i).attr(pole).toString().split(",");
var s = timeDifference(new Date(), new Date(date[0],date[1]-1,date[2],date[3],date[4],date[5]));
if (s.length) need_to_time_update.eq(i).html(s+options.end);
else need_to_time_update.eq(i).html(options.tolkochto);
});
}
};
timeUpdate();
var timer = setInterval(timeUpdate, intarval);
};
$("#countdown-example").timeUpdate('.need_to_time_update','time',1000);
</script>
<?if($_STATUS$)?>
<span time="<?if(substr($_LOG_TIME$,0,2)='Пн')?><?substr($_LOG_TIME$,19,4)?>,<?substr($_LOG_TIME$,16,2)?>,<?substr($_LOG_TIME$,13,2)?>,<?substr($_ LOG_TIME$,25,2)?>,<?substr($_LOG_TIME$,28,2)?>,00<?endif?><?if(substr($_LOG_TIME$,0,2)='Вт')?><?substr($_LOG_TIME$,15,4)?>,<?substr($_LOG_TI ME$,12,2)?>,<?substr($_LOG_TIME$,9,2)?>,<?substr($_LOG_TIME$,21,2)?>,<?substr($_LOG_TIME$,24,2)?>,00<?endif?><?if(substr($_LOG_TIME$,0,2)='С р')?><?substr($_LOG_TIME$,13,4)?>,<?substr($_LOG_TIME$,10,2)?>,<?substr($_LOG_TIME$,7,2)?>,<?substr($_LOG_TIME$,19,2)?>,<?substr($_LOG_TIME$ ,22,2)?>,00<?endif?><?if(substr($_LOG_TIME$,0,2)='Че')?><?substr($_LOG_TIME$,15,4)?>,<?substr($_LOG_TIME$,12,2)?>,<?substr($_LOG_TIME$,9,2)? >,<?substr($_LOG_TIME$,21,2)?>,<?substr($_LOG_TIME$,24,2)?>,00<?endif?><?if(substr($_LOG_TIME$,0,2)='Пя')?><?substr($_LOG_TIME$,15,4)?>,<?su bstr($_LOG_TIME$,12,2)?>,<?substr($_LOG_TIME$,9,2)?>,<?substr($_LOG_TIME$,21,2)?>,<?substr($_LOG_TIME$,24,2)?>,00<?endif?><?if(substr($_LOG_ TIME$,0,2)='Су')?><?substr($_LOG_TIME$,15,4)?>,<?substr($_LOG_TIME$,12,2)?>,<?substr($_LOG_TIME$,9,2)?>,<?substr($_LOG_TIME$,21,2)?>,<?subst r($_LOG_TIME$,24,2)?>,00<?endif?><?if(substr($_LOG_TIME$,0,2)='Во')?><?substr($_LOG_TIME$,19,4)?>,<?substr($_LOG_TIME$,16,2)?>,<?substr($_LO G_TIME$,13,2)?>,<?substr($_LOG_TIME$,25,2)?>,<?substr($_LOG_TIME$,28,2)?>,00<?endif?>" class="need_to_time_update"></span>
<?else?>
<font style="color:green;">Online, сейчас на сайте</font>
<?endif?>