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

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 setTime()方法


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

Definition and Usage
定义与用法

The setTime() method is used to calculate a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970.
setTime() 方法可在170年1月1号这个时间的基础上加上或是减去指定的毫秒数。

Syntax
语法

dateObject.setTime(millisec)

Parameter
参数
Description
描述
millisec Required. A numeric value representing the milliseconds since midnight January 1, 1970. Can be a negative number
必选。代表相距1970年1月1号的毫秒数


Tips and Notes
提示与注意点

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


Example
举例

In this example we will add 77771564221 milliseconds to 1970/01/01 and display the new date and time:
在这个举例中我们将算出1970年1月1号向后的77771564221毫秒为什么时候:

<script type="text/javascript">
var d = new Date()
d.setTime(77771564221)
document.write(d)
</script>

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

Mon Jun 19 05:12:44 UTC+0200 1972 


Example
举例

In this example we will subtract 77771564221 milliseconds from 1970/01/01 and display the new date and time:
这个举例中我们将算出1970年1月1号向前77771564221毫秒是什么时候:

<script type="text/javascript">
var d = new Date()
d.setTime(-77771564221)
document.write(d)
</script>

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

Sat Jul 15 22:47:15 UTC+0200 1967


Try-It-Yourself Demos
尝试与演示

setTime()
Use setTime() to add milliseconds to 1970/01/01 and display the new date and time.
使用setTime()来给1970年1月1号加上相应的毫秒可以得出新的日期和时间

评论 (0) All

登陆 | 还没注册?