Javascript时间不会打印出来(date.js)

时间:2012-10-23 13:48:09

标签: javascript date time

我使用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>

我的页面上没有打印任何内容?为什么呢?

2 个答案:

答案 0 :(得分:1)

而不是

var d1 = date.parse(Date.today().addHours(6.0));

var d1 = new Date();
d1.setHours( d1.getHours() + 6 );
document.write( d1.toTimeString() );​

http://jsfiddle.net/P5RL6/

答案 1 :(得分:1)

parse用于将现有String解析为Date对象。请改用toString()

Date.today().toString("hh:mm")

另外,使用document.write写入文档,即:

<script>document.write(Date.today().toString("hh:mm"))</script>