当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript Intl.DateTimeFormat.supportedLocalesOf()用法及代码示例


Intl.DateTimeFormat.supportedLocalesOf()方法是JavaScript中的内置方法,该方法返回一个数组,其中包含日期和时间格式支持的提供的语言环境。

用法:

Intl.DateTimeFormat.supportedLocalesOf(locales, options)

参数:此方法接受上面提到并在下面描述的两个参数:

  • locales:此参数包含带有BCP 47语言标记的字符串或此类字符串的数组。
  • options:它是一个可选参数。它是一个具有localeMatcher属性的对象。 localeMatcher是要使用的语言环境匹配算法。它的值为“lookup”和“best fit”。

返回值:此方法返回一个字符串数组,该字符串表示日期和时间格式支持的给定语言环境标签的子集。

以下示例说明了JavaScript中的Intl.DateTimeFormat.supportedLocalesOf()方法:



范例1:

<script> 
const geeks = ['ban', 'id-u-co-pinyin', 'de-ID']; 
const result = { localeMatcher:'lookup' }; 
let val = Intl.DateTimeFormat.supportedLocalesOf(geeks, result); 
console.log(val[0], val[1]); 
</script>

输出:

"id-u-co-pinyin" "de-ID"

范例2:

<script> 
const geeks = ['ban', 'id-u-co-pinyin', 'de-ID']; 
let val = Intl.DateTimeFormat.supportedLocalesOf(geeks); 
console.log(val); 
</script>

输出:

Array ["id-u-co-pinyin", "de-ID"]

支持的浏览器:下面列出了Intl.DateTimeFormat.supportedLocalesOf()方法支持的浏览器:

  • 谷歌浏览器
  • Edge
  • Firefox
  • Opera
  • Safari

相关用法


注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 JavaScript | Intl.DateTimeFormat.supportedLocalesOf() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。