From d9e9adb5f80a819fe46349bcf6d1faec734b09cd Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:07:31 +0800 Subject: remove span tag in zh-CN --- .../reference/global_objects/date/parse/index.html | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html index 701f6fc103..9646b069da 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/date/parse/index.html @@ -52,7 +52,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/parse

由于在解析日期字符串时存在偏差会导致结果不一致,因此推荐始终手动解析日期字符串,特别是不同的ECMAScript实现会把诸如“2015-10-12 12:00:00”的字符串解析为NaN,UTC或者本地时间。

-

ECMAScript 5 ISO-8601 日期格式支持

+

ECMAScript 5 ISO-8601 日期格式支持

另外,日期时间字符串也可以使用 ISO 8601 格式。例如,"2011-10-10" (仅日期)或 "2011-10-10T14:48:00" (日期和时间)能够作为参数被传递和解析。 如果参数字符串只包含日期格式,那么将会使用UTC时区来解析该参数。而如果是ISO 8601 格式中规定的时间加日期的格式,则将会被作为本地时区处理。

@@ -70,26 +70,26 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/parse

但是, 在如 ECMA-262 规范中定义的情况,如果因为无效值而导致日期字符串不能被识别为 ISO 格式时,根据浏览器和给定的值不同,返回值可以是,也可以不是 {{jsxref("NaN")}} 。比如:

-
// 包含无效值的非 ISO 格式字符串
-new Date('23/25/2014');
+
// 包含无效值的非 ISO 格式字符串
+new Date('23/25/2014');

在 Firefox 30 中会被识别为本地时区的2015年12月25日,而在 Safari 7 中则是无效日期。但是,如果字符串被识别为 ISO 格式并且包含无效值,则在所有遵循 ES5 或者更新标准的浏览器中都会返回 {{jsxref("NaN")}} 。

-
// 包含无效值的 ISO 格式字符串
-new Date('2014-25-23').toISOString();
-// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"
+
// 包含无效值的 ISO 格式字符串
+new Date('2014-25-23').toISOString();
+// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"

SpiderMonkey 的引擎策略可以在 jsdate.cpp  中找到。字符串 "10 06 2014"  可以作为非 ISO 格式字符串使用自定义处理方式的例子。参见这篇关于解析如何进行的粗略纲要

-
new Date('10 06 2014');
+
new Date('10 06 2014');

将会被解析为本地时间 2014年10月6日,而不是6月10日。另一个例子

-
new Date('foo-bar 2014').toString();
-// 返回: "Invalid Date"
+
new Date('foo-bar 2014').toString();
+// 返回: "Invalid Date"
 
-Date.parse('foo-bar 2014');
-// 返回: NaN
+Date.parse('foo-bar 2014'); +// 返回: NaN

例子

@@ -97,7 +97,7 @@ Date.parse如果 IPOdate 是一个已经存在的 {{jsxref("Date")}} 对象,则可以把其设置为本地时间 1995年8月9日。如下:

-
IPOdate.setTime(Date.parse('Aug 9, 1995'));
+
IPOdate.setTime(Date.parse('Aug 9, 1995'));

其他一些解析非标准格式日期的例子:

-- cgit v1.2.3-54-g00ecf