当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript getTime()方法

JavaScript
JS 字符串
JS Date
JS数组,JS Array
JS Boolean
JS Math
JS HTML DOM
JS Browser
JS Cookies
JS 校验
JS Animation
JS Image Maps
JS Timing
JS 建立对象
JS 摘要
JS 实例
JS 对象实例
JS DOM 实例
JS数组对象参考
JS布尔对象参考
JS日期对象参考

JavaScript getTime()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 306 ::
收藏到网摘: n/a

Definition and Usage
定语与用法

The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
getTime()方法所返回了从1970年1月1号以来所积累的毫秒总数

Syntax
语法

dateObject.getTime()


Tips and Notes
提示与注意点

Note: This method is always used in conjunction with a Date object.
注意:这个方法得结合Date对象使用


Example
举例

In this example we will get how many milliseconds since 1970/01/01 and print it:
在这个举例中我们得到了从1970年1月1号以来所积累的毫秒总数并输出它:

<script type="text/javascript">
var d = new Date()
document.write(d.getTime() + " milliseconds since 1970/01/01")
</script>

The output of the code above will be:
输出的结果为:



Example 2
举例 2

In the following example we will calculate the number of years since 1970/01/01:
在这个举例中我们得到了从1970年1月1号以来所用掉的年数总数并输出它:

<script type="text/javascript">
var minutes = 1000*60
var hours = minutes*60
var days = hours*24
var years = days*365
var d = new Date()
var t = d.getTime()
var y = t/years
document.write("It's been: " + y + " years since 1970/01/01!")
</script>

The output of the code above will be:
输出结果为:



Try-It-Yourself Demos
尝试与演示

getTime()
Use getTime() to calculate the years since 1970.
使用getTime() 来计算从1970年到现在过去了多少年

评论 (0) All

登陆 | 还没注册?