JavaScript是一门Web编程语言,用来实现网页的交互功能,它和HTML、CSS共同组成了个Web开发的基础工具集合,也是前端开发者必备的技能;学习JavaScript教程可以了解它在网页开发中的所有特性和相关概念,让我们能够更加快速的去开发Web应用。
这个getTime() 方法用于根据本地时间获取给定日期的毫秒数。
getTime()方法返回的值为自1970年1月1日00:00:00至今经过的毫秒数。
版本实现
实现于JavaScript 1.0
语法说明
getTime()
执行一下示例:
在以下网页文档中getTime() 方法计算两个时间点之间经过的毫秒数date.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>JavaScript date object - getTime() method example</title>
</head>
<body>
<h1 style="color: red">JavaScript date object : getTime() method</h1>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
fdate2002 = new Date(2008,1,1,0,0,0,0);
ldate2009 = new Date(2009,1,1,0,0,0,0);
document.write('Milliseconds passed between 1-1-2009 and 1-1-2008 : '+(ldate2009.getTime()-fdate2002.getTime()))
//]]>
</script>
</body>
</html>
执行一下支持的浏览器
IE浏览器7 | 火狐3.6 | 谷歌Chrome 7 | Safari 5.0.1 版 | Opera 10 |
Yes | Yes | Yes | Yes | Yes |
另请参阅:
上一篇:JavaScript getSeconds() 方法:日期对象