返回到:JavaScript对象:JavaScript Date 对象
定义和用法
toDateString() 方法可把 Date 对象的日期部分转换为字符串,并返回结果。
所有主要浏览器都支持 toDateString() 方法
语法
Date.toDateString()返回值
| 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.toDateString();
}
</script>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/jsarrtips/3340.html
支付宝
微信