當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Javascript Intl.DateTimeFormat.prototype.resolvedOptions()用法及代碼示例

Intl.DateTimeFormat.prototype.resolvedOptions() 方法是 JavaScript 中的一個內置方法,它返回一個新對象,該對象具有反映在此 DateTimeFormat 對象初始化期間計算的區域設置、日期和時間格式選項的屬性。

用法:

dateTimeFormat.resolvedOptions()

參數:此方法不接受任何參數。

返回值:此方法返回一個具有反映區域設置和日期和時間的屬性的新對象。

下麵的例子說明了 JavaScript 中的 Intl.DateTimeFormat.prototype.resolvedOptions() 方法:



範例1:


const geeks = new Intl.DateTimeFormat('zh-CN', { timeZone:'UTC' });
const result = geeks.resolvedOptions();
console.log(result.locale);
console.log(result.calendar);
console.log(result.timeZone);
  
const geeks1 = new Intl.DateTimeFormat('LT');
const result1 = geeks1.resolvedOptions();
console.log(result1.locale);
console.log(result1.calendar);

輸出:

"zh-CN"
"gregory"
"UTC"
"lt"
"gregory"

範例2:


var geeks = new Intl.DateTimeFormat('de-XX', { timeZone:'UTC' });
var result = geeks.resolvedOptions();
  
console.log(result.locale);       
console.log(result.calendar);       
console.log(result.numberingSystem); 
console.log(result.timeZone);        
console.log(result.month); 

輸出:

"de"
"gregory"
"latn"
"UTC"
"numeric"

支持的瀏覽器: Intl.DateTimeFormat.prototype.resolvedOptions() 方法支持的瀏覽器如下:

  • 穀歌瀏覽器
  • Edge
  • Firefox
  • Opera
  • Safari

相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 JavaScript | Intl.DateTimeFormat.prototype.resolvedOptions() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。