2 xiuxiu567 xiuxiu567 于 2016.04.12 16:31 提问

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);

2个回答

CSDNXIAON
CSDNXIAON   2016.04.12 16:43
已采纳

js 时间Date
js中获取时间new Date()
js中的New Date获取各种时间
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

showbo
showbo   Ds   Rxr 2016.04.12 16:38
 var urodz = new Date("a");
===>
var urodz = new Date(a.replace(/-/g, '/'));//字符串作为Date参数注意格式为 2016/4/12,不能是2016-4-12,要不报错

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!