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

JavaScript
JS 介绍
JS 怎样使用
JS 在哪使用
JS 变量
JS If...Else
JS Switch
JS 操作符
JS Popup Boxes
JS 函数
JS For 循环
JS While 循环
JS Break 循环
JS For...In
JS 事件
JS Try...Catch
JS Throw
JS onerror
JS 特殊字符
JS Guidelines
JS 对象介绍

JavaScript getTime()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 305 ::
收藏到网摘: 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

登陆 | 还没注册?