До часа Х осталось
пример работы скрипта:
пример html-кода:
<script type="text/javascript">
function getDaysLeft(oDeadLineDate, oToday)
{
return oDeadLineDate > oToday ? Math.ceil((oDeadLineDate - oToday) / (1000 * 60 * 60 * 24)) : null;
}
function MkDaysLeft(sDeadLineDate, sDeadLineText)
{
var oToday = new Date();
var sTime = sDeadLineDate + " " + oToday.getHours() + ":" + oToday.getMinutes() + ":" + oToday.getSeconds();
var oDeadLineDate = new Date(sTime);
var nDaysLeft = getDaysLeft(oDeadLineDate, oToday);
if (nDaysLeft)
{
var sDaysLeft = String(nDaysLeft);
var sDaysText = "дней";
var nDaysLeftLength = sDaysLeft.length;
if (sDaysLeft.charAt(nDaysLeftLength - 2) != "1")
{
if (sDaysLeft.charAt(nDaysLeftLength - 1) == "2" || sDaysLeft.charAt(nDaysLeftLength - 1) == "3" || sDaysLeft.charAt(nDaysLeftLength - 1) == "4")
{
sDaysText = "дня";
}
else if (sDaysLeft.charAt(nDaysLeftLength - 1) == "1")
{
sDaysText = "день";
}
}
var sLeftText = sDaysText == "день" ? "остался" : "осталось";
document.write(sDeadLineText + " " + sLeftText + " " + nDaysLeft + " " + sDaysText + ".");
}
else
{
document.write("С Новым годом!");
}
}
MkDaysLeft("December 31, 2007", "До Нового года");алось
</script>





