返回到:JavaScript对象:JavaScript Date 对象
定义和用法
toTimeString() 方法可把 Date 对象的时间部分转换为字符串,并返回结果。
所有主要浏览器都支持toTimeString() 方法
语法
Date.toTimeString()Return Value
| Type | 描述 |
|---|---|
| String | 时间作为字符串输出 |
实例
把 Date 对象的时间部分转换为字符串:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程(Web176.com)</title>
</head>
<body>
<p id="demo">单击按钮来显示时间为字符串。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML=d.toTimeString();
}
</script>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/jsarrtips/3356.html
支付宝
微信