2017-02-28 7 views
-1

私は、それぞれに異なるタイムゾーンを持つデジタル時計をいくつか作っています。私は時計で終わっています。今は、ユーザータイムロケールの設定を表示したいと思っています。だから、ヨーロッパにいる間に09:00 PMを示すのはアメリカでは21:00です。ユーザ時間ロケール設定 - javaScript(momentjs)?

var elementsDigital = document.querySelectorAll("div[data-timezone]"); 
Array.prototype.forEach.call(elementsDigital, function(elem) { 
    var timezone = elem.getAttribute("data-timezone"); 
    elem.querySelector(".time").textContent = moment.tz(timezone).locale("en").format("LT"); 
}); 

基本的にこのコードはただのいくつかのタイムゾーンは、HTMLであなたのdata-timezoneに何をもとにしてから使用して取得:ここ

はここでクロック

enter image description here

の絵がコードでありますmoment.jsのロケールは英語にタイムゾーンを変換し、ちょうど時分であるLTの形式を表示します。

私のことを分かりやすいように、ユーザーのローカルタイム設定に基づいて、さまざまなタイムゾーンを時計に表示したいと考えています。だから01:00 PMアメリカ、ヨーロッパ13:00など。ただ、

var elementsDigital = document.querySelectorAll("div[data-timezone]"); 
Array.prototype.forEach.call(elementsDigital, function(elem) { 
    var timezone = elem.getAttribute("data-timezone"); 
    elem.querySelector(".time").textContent = moment.tz(timezone).locale(window.navigator.userLanguage || window.navigator.language).format("LT"); 
});` 

:答えが見つかり

+0

は、ここで質問がありますか?私は疑問を見ない。 –

答えて

0

window.navigator.userLanguage || window.navigator.language

関連する問題