JavaScript对象:JavaScript toTimeString() 方法

返回到: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

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2021年9月1日 下午5:31
下一篇 2021年9月1日 下午5:36

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注