2014-09-26 51 views
1

我需要將我的Chrome瀏覽器運行的JavaScript語言環境從英語美國更改爲英國英語,以便測試依賴於javascript的Date對象的功能。這是基於瀏覽器設置嗎?或者我的操作系統設置?我在Windows 7更改測試的當前語言環境

回答

-1

運行,你可以插入代碼的這一和平在你頁面的頭部被首先執行:

var bind = Function.bind; 
var unbind = bind.bind(bind); 

function instantiate(constructor, args) { 
    return new (unbind(constructor, null).apply(null, args)); 
} 

var offset = 5; 
Date = function (Date) { 
    return function() { 
     var date = instantiate(Date, arguments); 
     utc = date.getTime() + (date.getTimezoneOffset() * 60000); 
     nd = new Date(utc + (3600000*offset)); 
     nd = new Date(Date.UTC(nd.getFullYear(), nd.getMonth(), nd.getDate(), nd.getHours(), nd.getMinutes(), nd.getSeconds())); 
     return nd; 
    } 
}(Date); 

new Date('01.31.2014 15:34:12') 
// Fri Jan 31 2014 20:34:12 GMT+0200 (E. Europe Standard Time) 

它的工作原理,但輸出不能更改時區。

它覆蓋原生Date的構造函數,在時區中返回一個Date,偏移量爲2,倫敦時間。

+0

你能解釋一下這是如何工作的嗎?我沒有在代碼中看到特別提到語言環境的任何內容。 – 2014-09-26 19:04:50

+0

此代碼可能會改變您的時區。所以,如果英文時區爲0,那麼美國是9或者像那樣。變量偏移使用時區編號。該代碼不會更改區域設置。 – heroin 2014-09-26 19:21:18

+0

對不起,在我的問題中,我特別在尋找如何更改區域設置。 – 2014-09-29 15:02:03

1

最簡單的方法,並改變你的Chrome瀏覽器的區域設置的最佳方法是:

  1. 就到你的桌面谷歌瀏覽器快捷方式,右鍵單擊和屬性。 你會發現你的目標有:根據您的區域,你會想改變

     
    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --lang=en_US --user-data-dir=C:\ChromeUserDirs\EN_US 
    

    等:目標"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

  2. 更改爲。

正如您所看到的,我已將我的區域設置(默認爲英語,因爲我住在英國)更改爲美國。

相關問題