返回到:JavaScript对象:JavaScript Date 对象
定义和用法
getMilliseconds() 方法可返回时间的毫秒。
所有主要浏览器都支持 getMilliseconds() 方法
语法
Date.getMilliseconds()
返回值
类型 | 描述 |
---|---|
Number | 返回值是 0 ~ 999 之间的一个整数,该数字代表毫秒数。 |
技术细节
JavaScript 版本: | 1.3 |
---|
实例
DEMO1:根据当地时间返回时间的毫秒。
HTML
x
20
20
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>Web176教程(Web176.com)</title>
6
</head>
7
<body>
8
9
<p id="demo">单击按钮显示此时时间的毫秒数:</p>
10
<button onclick="myFunction()">点我</button>
11
<script>
12
function myFunction(){
13
var d = new Date();
14
var x = document.getElementById("demo");
15
x.innerHTML=d.getMilliseconds();
16
}
17
</script>
18
19
</body>
20
</html>
DEMO2:返回指定时间内的毫秒数。
HTML
xxxxxxxxxx
1
20
20
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>Web176教程(Web176.com)</title>
6
</head>
7
<body>
8
9
<p id="demo">单击按钮显示给定时间的毫秒数:</p>
10
<button onclick="myFunction()">点我</button>
11
<script>
12
function myFunction(){
13
var d = new Date("July 21, 1983 01:15:00:526");
14
var x = document.getElementById("demo");
15
x.innerHTML=d.getMilliseconds();
16
}
17
</script>
18
19
</body>
20
</html>
试试吧!!!
阅读剩余 62%
作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/jsarrtips/3259.html