我使用date.js获得以下代码:
<div id="Timer">
<script>Date.parse("hh:mm");</script>
<div class="Timers">
<div class="timerSpace"><span style="text-align: left; color: #DDDD11;">Hours from now</span></div>
<div class="timer1"><span style="color: #FFFF11;"><script>var d1 = date.parse(Date.today().addHours(6.0)); document.write(d1);</script><span></div>
<div class="timer2"><span style="color: #FFFF11;"><script>var d2 = date.parse(Date.today().addHours(12.0)); document.write(d2);</script><span></div>
<div class="timer3"><span style="color: #FFFF11;"><script>var d3 = date.parse(Date.today().addHours(18.0));document.write(d3);</script><span></div>
<div class="timer4"><span style="color: #FFFF11;"><script>var d4 = date.parse(Date.today().addHours(24.0));document.write(d4);</script><span></div>
<div class="timerSpace"></div>
</div>
</div>
我的页面上没有打印任何内容?为什么呢?
答案 0 :(得分:1)
而不是
var d1 = date.parse(Date.today().addHours(6.0));
试
var d1 = new Date();
d1.setHours( d1.getHours() + 6 );
document.write( d1.toTimeString() );
答案 1 :(得分:1)
parse
用于将现有String
解析为Date
对象。请改用toString()
:
Date.today().toString("hh:mm")
另外,使用document.write
写入文档,即:
<script>document.write(Date.today().toString("hh:mm"))</script>