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

JavaScript
JS数学对象参考
JS字符串对象参考
JS函数参考
JS事件参考
Javascript 常用正则表达式
FF和IE下的js兼容性问题
jQuery 简单介绍
jQuery / 核心 / $(expression, [context] ) 函数
jQuery / 核心 / $(html) 函数
如何使用JS来判断浏览器类型(ie、firefox,等等)
Javascript在IE和FireFox中的不同表现
3个js字符编码函数区别
javascript 中的 XMLDOM 对象

JavaScript setTime()方法


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

登陆 | 还没注册?