From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/date/todatestring/index.html | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.html new file mode 100644 index 0000000000..e2216ea015 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/todatestring/index.html @@ -0,0 +1,72 @@ +--- +title: Date.prototype.toDateString() +slug: Web/JavaScript/Reference/Global_Objects/Date/toDateString +translation_of: Web/JavaScript/Reference/Global_Objects/Date/toDateString +--- +
{{JSRef("Global_Objects", "Date")}}
+ +

toDateString() 方法以美式英语和人类易读的形式返回一个日期对象日期部分的字符串。

+ +
{{EmbedInteractiveExample("pages/js/date-todatestring.html")}}
+ + + +

语法

+ +
dateObj.toDateString()
+ +

描述

+ +

{{jsxref("Global_Objects/Date", "Date")}} 对象实例引用一个具体的时间点。调用 {{jsxref("Date.toString", "toString")}} 方法会以美式英语和人类易读的形式返回日期对象的格式化字符串。在 SpiderMonkey 里,该字符串由日期部分(年月日)和其后的时间部分(时分秒及时区)组成。有时需要获取日期部分的字符串,这可以由 toDateString 方法完成。

+ +

The toDateString method is especially useful because compliant engines implementing ECMA-262 may differ in the string obtained from toString for Date objects, as the format is implementation-dependent and simple string slicing approaches may not produce consistent results across multiple engines.

+ +

例子

+ +

例子:toDateString 方法的简单使用

+ +
var d = new Date(1993, 6, 28, 14, 39, 7);
+
+println(d.toString());     // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
+println(d.toDateString()); // prints Wed Jul 28 1993
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
规范版本规范状态注解
ECMAScript 3rd Edition.StandardInitial definition.
{{SpecName('ES5.1', '#sec-15.9.5.3', 'Date.prototype.toDateString')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-date.prototype.todatestring', 'Date.prototype.toDateString')}}{{Spec2('ES6')}} 
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.Date.toDateString")}}

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf