aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html286
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html119
2 files changed, 405 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html b/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html
new file mode 100644
index 0000000000..ef43816d44
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/index.html
@@ -0,0 +1,286 @@
+---
+title: Intl.DateTimeFormat
+slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
+translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
+---
+<div>{{JSRef}}</div>
+
+<div><strong><code>Intl.DateTimeFormat</code></strong>是根据语言来格式化日期和时间的对象的构造器。</div>
+
+<div>{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html")}}</div>
+
+<p class="hidden">交互示例的源代码存储在 GitHub 资源库。如果你愿意分布交互示例,请复制<a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a>,并向我们发送一个pull请求。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><code>new Intl.DateTimeFormat([<var>locales</var>[, <var>options</var>]])
+Intl.DateTimeFormat.call(<var>this</var>[, <var>locales</var>[, <var>options</var>]])</code></pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>locales</code></dt>
+ <dd>
+ <p>可选.缩写语言代码(BCP 47 language tag,例如:cmn-Hans-CN)的字符串或者这些字符串组成的数组. 关于参数locales的一般形式和解释请参见{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_identification_and_negotiation", 1)}}. 下面的这些Unicode扩展键也是被允许的:</p>
+
+ <p>译者注:下面这两种扩展的使用方式是language[-scripts][-region]-u-nu-* 和 language[-scripts][-region]-u-ca-* ,例如:zh-u-nu-hanidec(表示中文十进制数字) 和 zh-u-ca-chinese(表示中国日历,比如壬辰年冬月8日) ,也可以 nu 和 ca 组合使用 比如 使用 zh-u-ca-chinese-nu-hanidec 格式化Date.now()的返回值类似于"丙申年冬月九日"</p>
+
+ <p><code>nu</code></p>
+
+ <dl>
+ <dd>编号系统. 可能的值包括: <code>"arab"</code>, <code>"arabext"</code>, <code>"bali"</code>, <code>"beng"</code>, <code>"deva"</code>, <code>"fullwide"</code>, <code>"gujr"</code>, <code>"guru"</code>, <code>"hanidec"</code>, <code>"khmr"</code>, <code>"knda"</code>, <code>"laoo"</code>, <code>"latn"</code>, <code>"limb"</code>, <code>"mlym"</code>, <code>"mong"</code>, <code>"mymr"</code>, <code>"orya"</code>, <code>"tamldec"</code>, <code>"telu"</code>, <code>"thai"</code>, <code>"tibt"</code>.</dd>
+ <dt><code>ca</code></dt>
+ <dd>日历. 可能的值包括: <code>"buddhist"</code>, <code>"chinese"</code>, <code>"coptic"</code>, <code>"ethioaa"</code>, <code>"ethiopic"</code>, <code>"gregory"</code>, <code>"hebrew"</code>, <code>"indian"</code>, <code>"islamic"</code>, <code>"islamicc"</code>, <code>"iso8601"</code>, <code>"japanese"</code>, <code>"persian"</code>, <code>"roc"</code>.</dd>
+ </dl>
+ </dd>
+ <dt><code>options</code></dt>
+ <dd>
+ <p>可选. 包含一些或所有的下面属性的类:</p>
+
+ <dl>
+ <dt><code>localeMatcher</code></dt>
+ <dd>使用的local的匹配算法. 可能的值有"lookup"和"best fit"; 默认值是 <code>"best fit"</code>. 有关此选项的信息, 请参见{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}}.</dd>
+ <dt><code>timeZone</code></dt>
+ <dd>使用的时区. 这唯一的值实现必须被标准世界时间(UTC)所识别。默认值是运行时的默认时区. <a href="https://www.iana.org/time-zones">IANA time zone database</a>中的时区名称可能会被识别, 例如<code>"Asia/Shanghai"</code>, <code>"Asia/Kolkata"</code>, <code>"America/New_York"</code>.</dd>
+ <dt><code>hour12</code></dt>
+ <dd>是否使用12小时时间制(而不是24小时的时间). 可能的值是<code>true</code> 或 <code>false</code>; 默认值是根据locale来自动决定的(译者注:中国地区的默认值为true).</dd>
+ <dt><code>formatMatcher</code></dt>
+ <dd><code>format的匹配算法.可能的值有"basic"和"best fit";默认值是"best fit".有关此属性使用的信息,参见以下段落。</code></dd>
+ <dd>
+ <p>日期时间插件被格式化输出时可以使用的属性集合描述。实现需要支持是以下子集中的其中一个(译者注:当weekday,year等这些属性一个也不使用的时候,在cmn-Hans-CN中相当于使用集合year, month, day, hour, minute, second并且它们的值都是numeric):</p>
+ </dd>
+ </dl>
+
+ <ul>
+ <li><code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code>, <code>hour</code>, <code>minute</code>, <code>second</code></li>
+ <li><code>weekday</code>, <code>year</code>, <code>month</code>, <code>day</code></li>
+ <li><code>year</code>, <code>month</code>, <code>day</code></li>
+ <li><code>year</code>, <code>month</code></li>
+ <li><code>month</code>, <code>day</code></li>
+ <li><code>hour</code>, <code>minute</code>, <code>second</code></li>
+ <li><code>hour</code>, <code>minute</code></li>
+ </ul>
+
+ <p>实现可能支持其他的子集,并通过对所有可用的子集对比找到最匹配的子集。通过 formatMatcher属性可以设置两种算法用于对比和选择子集:  <a href="http://www.ecma-international.org/ecma-402/1.0/#BasicFormatMatcher">完全匹配<code>"basic"算法</code> </a> 和 一种依赖于“best fit”算法的实现.</p>
+
+ <dl>
+ <dt><code>weekday</code></dt>
+ <dd>工作日的展现方式.可能的值有 <code>"narrow"</code>, <code>"short"</code>, <code>"long"</code>.</dd>
+ <dt><code>era</code></dt>
+ <dd>纪元的展现方式. 可能的值有 <code>"narrow"</code>, <code>"short"</code>, <code>"long"</code>.</dd>
+ <dt><code>year</code></dt>
+ <dd>年的展现方式.  可能的值有 <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
+ <dt><code>month</code></dt>
+ <dd>月的展现方式. 可能的值有 <code>"numeric"</code>, <code>"2-digit"</code>, <code>"narrow"</code>, <code>"short"</code>, <code>"long"</code>.</dd>
+ <dt><code>day</code></dt>
+ <dd>日的展现方式.可能的值有 <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
+ <dt><code>hour</code></dt>
+ <dd>时的展现方式.可能的值有 <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
+ <dt><code>minute</code></dt>
+ <dd>分钟的展现方式.可能的值有 <code>"numeric"</code>, <code>"2-digit"</code>.</dd>
+ <dt><code>second</code></dt>
+ <dd>秒的展现方式. 可能的值有<code>"numeric"</code>, <code>"2-digit"</code>.</dd>
+ <dt><code>timeZoneName</code></dt>
+ <dd>时区名称的展现方式.可能的值有 <code>"short"</code>, <code>"long"</code>.</dd>
+ </dl>
+
+ <p class="noinclude">每个日期时间组件属性的默认值都是{{jsxref("undefined")}},但是若所有的组件属性都是{{jsxref("undefined")}},那么<code>year</code>, <code>month</code>, and <code>day</code> 的值就都被认为是"<code>numeric</code>".</p>
+ </dd>
+</dl>
+
+<h2 id="描述">描述</h2>
+
+<h3 id="属性">属性</h3>
+
+<dl>
+ <dt>{{jsxref("DateTimeFormat.prototype", "Intl.DateTimeFormat.prototype")}}</dt>
+ <dd>允许将属性添加到所有对象上。</dd>
+</dl>
+
+<h3 id="方法">方法</h3>
+
+<dl>
+ <dt>{{jsxref("DateTimeFormat.supportedLocalesOf", "Intl.DateTimeFormat.supportedLocalesOf()")}}</dt>
+ <dd>Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.</dd>
+</dl>
+
+<h2 id="DateTimeFormat_实例"><code>DateTimeFormat</code> 实例</h2>
+
+<h3 id="属性_2">属性</h3>
+
+<p><code>DateTimeFormat实例集成以下原型的属性</code>:</p>
+
+<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/prototype', 'Properties')}}</div>
+
+<h3 id="方法_2">方法</h3>
+
+<p><code>DateTimeFormat实例集成以下原型的方法</code>:</p>
+
+<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/prototype', 'Methods')}}</div>
+
+<h2 id="实例">实例</h2>
+
+<h3 id="使用_DateTimeFormat">使用 <code>DateTimeFormat</code></h3>
+
+<p>不指定locale时,DateTimeFormat使用默认的locale 和 默认的 options</p>
+
+<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
+
+//参数未填时使用默认的locale和默认的时区
+console.log(new Intl.DateTimeFormat().format(date));
+//如果是在洛杉矶那么值为 → "12/19/2012"
+</pre>
+
+<h3 id="使用locales">使用<code>locales</code></h3>
+
+<p>这个例子显示了本地化日期和时间格式的一些变化。为了获得用于您的应用程序的用户界面的语言格式,请确保使用locales参数确保指定语言(可能还有一些回退语言):</p>
+
+<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
+
+// 下面是假定的所在时区
+// 洛杉矶(America/Los_Angeles for the US)
+
+// 美式英语(US English) 使用 month-day-year 格式
+console.log(new Intl.DateTimeFormat('en-US').format(date));
+// → "12/19/2012"
+
+// 英式英语(British English) 使用 day-month-year 格式
+console.log(new Intl.DateTimeFormat('en-GB').format(date));
+// → "20/12/2012"
+
+// 韩国使用 year-month-day 格式
+console.log(new Intl.DateTimeFormat('ko-KR').format(date));
+// → "2012. 12. 20."
+
+//大部分阿拉伯国家使用阿拉伯字母(real Arabic digits)
+console.log(new Intl.DateTimeFormat('ar-EG').format(date));
+// → "<span dir="rtl">٢٠‏/١٢‏/٢٠١٢</span>"
+
+//在日本,应用可能想要使用日本日历,
+//2012 是平成24年(平成是是日本天皇明仁的年号,由1989年1月8日起开始计算直至现在)
+console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date));
+// → "平成24/12/20"
+
+//当请求一个语言可能不支持,如巴厘(ban),若有备用的语言印尼语(id),
+//那么将使用印尼语(id)
+console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date));
+// → "20/12/2012"
+</pre>
+
+<h3 id="使用options">使用<code>options</code></h3>
+
+<p>可以使用 <code>options </code>参数来自定义 <font face="Consolas, Liberation Mono, Courier, monospace">日期时间格式化</font>方法返回的字符串。</p>
+
+<pre class="brush: js">var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
+
+//请求参数(options)中包含参数星期(weekday),并且该参数的值为长类型(long)
+var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
+console.log(new Intl.DateTimeFormat('de-DE', options).format(date));
+// → "Donnerstag, 20. Dezember 2012"
+
+// 一个应用使用 世界标准时间(UTC),并且UTC使用短名字(short)展示
+options.timeZone = 'UTC';
+options.timeZoneName = 'short';//若不写这一行那么仍然显示的是世界标准时间;但是GMT三个字母不会显示
+console.log(new Intl.DateTimeFormat('en-US', options).format(date));
+// → "Thursday, December 20, 2012, GMT"
+
+// 有时你想变得更精确
+options = {
+ hour: 'numeric', minute: 'numeric', second: 'numeric',
+ timeZoneName: 'short'
+};
+console.log(new Intl.DateTimeFormat('en-AU', options).format(date));
+// → "2:00:00 pm AEDT"
+
+// 使用24小时制
+options = {
+ year: 'numeric', month: 'numeric', day: 'numeric',
+ hour: 'numeric', minute: 'numeric', second: 'numeric',
+ hour12: false
+};
+console.log(date.toLocaleString('en-US', options));
+// → "12/19/2012, 19:00:00"
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范版本</th>
+ <th scope="col">规范状态</th>
+ <th scope="col">注解</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int 1.0', '#sec-12.1', 'Intl.DateTimeFormat')}}</td>
+ <td>{{Spec2('ES Int 1.0')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int 2.0', '#sec-12.1', 'Intl.DateTimeFormat')}}</td>
+ <td>{{Spec2('ES Int 2.0')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int Draft', '#datetimeformat-objects', 'Intl.DateTimeFormat')}}</td>
+ <td>{{Spec2('ES Int Draft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome("24")}}</td>
+ <td>{{CompatGeckoDesktop("29")}}</td>
+ <td>{{CompatIE("11")}}</td>
+ <td>{{CompatOpera("15")}}</td>
+ <td>{{CompatSafari("10")}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome("26")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatSafari("10")}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="相关链接">相关链接</h2>
+
+<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl', 'See_also')}}</div>
diff --git a/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html b/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html
new file mode 100644
index 0000000000..d8cb843c33
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html
@@ -0,0 +1,119 @@
+---
+title: Intl.DateTimeFormat.prototype
+slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/prototype
+translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>Intl.DateTimeFormat.prototype</code></strong>表示 {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}构造函数的原型对象。</p>
+
+<p>{{js_property_attributes(0, 0, 0)}} </p>
+
+<h2 id="描述">描述</h2>
+
+<p>参见 {{jsxref("DateTimeFormat")}}来看<code>Intl.DateTimeFormat实例的一个描述。</code></p>
+
+<p>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} 实例继承自<code>Intl.DateTimeFormat.prototype</code>. 对原型对象的修改都继承自{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}实例。</p>
+
+<h2 id="属性">属性</h2>
+
+<dl>
+ <dt><code>Intl.DateTimeFormat.prototype.constructor</code></dt>
+ <dd>请参考 {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}.</dd>
+ <dt>{{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format")}}</dt>
+ <dd>Getter; 返回一个{{jsxref("DateTimeFormat", "DateTimeFormat")}}对象的根据locale和格式化参数格式化日期的函数。</dd>
+</dl>
+
+<h2 id="方法">方法</h2>
+
+<dl>
+ <dt>{{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}</dt>
+ <dd>Returns an {{jsxref("Array")}} of objects representing the date string in parts that can be used for custom locale-aware formatting.</dd>
+ <dt>{{jsxref("DateTimeFormat.resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}</dt>
+ <dd>返回一个新的属性对象,反射出在对象初始化过程中计算出的locale和options的各个值。</dd>
+</dl>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范版本</th>
+ <th scope="col">规范状态</th>
+ <th scope="col">注解</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int 1.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}</td>
+ <td>{{Spec2('ES Int 1.0')}}</td>
+ <td>初始定义</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int 2.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}</td>
+ <td>{{Spec2('ES Int 2.0')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES Int Draft', '#sec-Intl.DateTimeFormat.prototype', 'Intl.DateTimeFormat.prototype')}}</td>
+ <td>{{Spec2('ES Int Draft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatChrome("24")}}</td>
+ <td>{{CompatGeckoDesktop("29")}}</td>
+ <td>{{CompatIE("11")}}</td>
+ <td>{{CompatOpera("15")}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome("26")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li>
+</ul>