Intl 對象是 ECMAScript 國際化 API 的一個命名空間,它提供了精確的字符串對比(Collator )凹耙,數(shù)字格式化(NumberFormat),日期和時間格式化(DateTimeFormat)奋献。
Intl.Collator 是用于語言敏感字符串比較的 collators構(gòu)造函數(shù)案训。
詳細(xì)參考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Collator
Intl.DateTimeFormat是根據(jù)語言來格式化日期和時間的類的構(gòu)造器類
參考鏈接:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
實(shí)例:
vardate =newDate();//參數(shù)未填時使用默認(rèn)的locale和默認(rèn)的時區(qū)console.log(newIntl.DateTimeFormat().format(date));//2017/01/01Intl.NumberFormat是對語言敏感的格式化數(shù)字類的構(gòu)造器類
詳細(xì)參考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
varnumber =123456.00;// 通過編號系統(tǒng)中的nu擴(kuò)展鍵請求, 例如中文十進(jìn)制數(shù)字console.log(newIntl.NumberFormat('zh-Hans-CN-u-nu-hanidec').format(2));//二// 請求一個貨幣格式console.log(newIntl.NumberFormat('zh-Hans-CN', {style:'currency',currency:'CNY'}).format(number));//¥123,456.00
轉(zhuǎn)載自http://www.reibang.com/p/e649423944cf