javascript倒计时器新日期

时间:2011-10-20 06:30:18

标签: javascript asp.net

我正在使用javascript作为倒计时器

<script type="text/javascript">
        $(function() {
        var newYear = $(".HF").val();
            alert('hehe' + newYear);
            $('#countdown').countdown({ until:newYear, format: 'DHMS', layout:
'<div id="timer">' + '<hr />' +
    '<div id="timer_days" class="timer_numbers">{dnn}</div>' +
    '<div id="timer_hours" class="timer_numbers">{hnn}</div>' +
    '<div id="timer_mins" class="timer_numbers">{mnn}</div>' +
    '<div id="timer_seconds" class="timer_numbers">{snn}</div>' +
'<div id="timer_labels">' +
    '<div id="timer_days_label" class="timer_labels">days</div>' +
    '<div id="timer_hours_label" class="timer_labels">hours</div>' +
    '<div id="timer_mins_label" class="timer_labels">mins</div>' +
    '<div id="timer_seconds_label" class="timer_labels">secs</div>' +
'</div>' +
'</div>'
            });
        });
</script>

它从隐藏字段HF获取它的值。隐藏字段的值是一个字符串10/22/2011 ...但是计时器只显示34分钟,而它必须显示2天几个小时,剩下几分钟......为什么?

1 个答案:

答案 0 :(得分:0)

newYear字符串必须转换为Date对象:

var newYear = $(".HF").val();
newYear = new Date(newYear); // 10/22/2011 > Dat object of 22 Okt 2011