myDate = new Date(); a = myDate.getFullYear() + 1; getDate = new Date(a, 0, 1); getDateMsec = getDate.getTime(); timer = function () { nowDate = new Date(); nowDateMsec = nowDate.getTime(); var p4 = getDateMsec - nowDateMsec; if (p4 <= 0) { timetxt.text = "С Новым Годом!"; clearInterval(interval); return; } // end if var sR = Math.floor(p4 / 1000); var mR = Math.floor(sR / 60); var hR = Math.floor(mR / 60); var dR = Math.floor(hR / 24); sR = sR % 60; mR = mR % 60; hR = hR % 24; if (sR < 10) { sR = "0" + sR; } // end if if (mR < 10) { mR = "0" + mR; } // end if if (hR < 10) { hR = "0" + hR; } // end if if (dR < 10) { dR = "0" + dR; } // end if days.text = dR; hours.text = hR; minutes.text = mR; seconds.text = sR; }; interval = setInterval(timer, 1000); timer();