那那哥
2016-04-12 08:31
采纳率: 79.5%
浏览 2.7k

js获取的时间怎么传到Date()中

html代码:

 <div class="time">

                    <form name=timeForm>

                        <input type="hidden" name=times value="{$stime}">

                        <span>距离结束仅剩:</span><span id="date"></span><span class="white14b">天</span><span id="time"></span>

                    </form>

                </div>
JS代码:
var now = new Date();
function GetServerTime()
{
var a  = document.timeForm.times.value;
var urodz = new Date("a");

now.setTime(now.getTime()+250);
days = (urodz - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (urodz - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (urodz - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
document.getElementById("date").innerHTML = daysRound;
document.getElementById("time").innerHTML = hoursRound + "时" + minutesRound + "分" + secondsRound + "秒";
}
setInterval("GetServerTime()",250);
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  •  var urodz = new Date("a");
    ===>
    var urodz = new Date(a.replace(/-/g, '/'));//字符串作为Date参数注意格式为 2016/4/12,不能是2016-4-12,要不报错
    
    
    打赏 评论

相关推荐 更多相似问题