From 563ca0a35e98678e2b7d5f154f31f496851e8d60 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:07 +0800 Subject: remove code tag inside pre tag for zh-CN --- .../reference/global_objects/date/parse/index.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 68a8d136e7..5b0a6cf01d 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 @@ -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 格式字符串
+
// 包含无效值的 ISO 格式字符串
 new Date('2014-25-23').toISOString();
-// 在所有遵循 ES5的浏览器中返回 "RangeError: invalid date"
+// 在所有遵循 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();
+
new Date('foo-bar 2014').toString();
 // 返回: "Invalid Date"
 
 Date.parse('foo-bar 2014');
-// 返回: NaN
+// 返回: NaN

例子

@@ -97,7 +97,7 @@ Date.parse('foo-bar 2014');

如果 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