使用Moment或Internationalization API时更正时区列表 [英] Correct timezone list when using Moment or Internationalization API
本文介绍了使用Moment或Internationalization API时更正时区列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用MomentJS或Internationalization API时,我会获得过时的时区,例如 Asia / Katmandu
或 Asia / Calcutta
in铬!这些应该输出为亚洲/加德满都
和亚洲/加尔各答
。
When I use MomentJS or Internationalization API, I get obsolete timezones like Asia/Katmandu
or Asia/Calcutta
in Chrome! These should instead be outputted as Asia/Kathmandu
and Asia/Kolkata
.
如何解决这个问题?
推荐答案
这里我写了一个非常小的代码来比较哪些可能对你有帮助您。我使用未分解的数据文件并提取整个数据。此列表将显示新数据和过时数据之间的比较。
Here I wrote a very small code to compare which might be helpful for you. I used unminified data file and extracted the whole data. This list will show you the comparison between new and obsolete data.
$("#div1").load("https://momentjs.com/downloads/moment-timezone-with-data.js", function(responseTxt, statusTxt, xhr) {
if (statusTxt == "success") {
//console.log("External content loaded successfully!");
keepMeUpdated();
}
if (statusTxt == "error")
console.log("Error: " + xhr.status + ": " + xhr.statusText);
});
function keepMeUpdated() {
var str = $("#div1").html();
str = str.slice(str.lastIndexOf("loadData"), str.length - 1);
str = str.slice(0, str.indexOf(')'));
str = str.replace('loadData(', '');
$("#div1").html(str);
compareNow();
}
function compareNow() {
var str = $("#div1").html();
var obj = JSON.parse(str);
var links = obj.links;
var counter = 0;
var te = "There are " + obj.zones.length + " timezones available. From these timezones " + links.length + " have recently got updated."
$("#head").html(te);
for (var i = 0; i < links.length; i++) {
var ele = links[i];
var spl = ele.split('|');
var isSame = spl[0] == spl[1];
if (!isSame) {
counter++;
var text = '<tr><td>' + counter + "</td><td>" + spl[1] + "</td><td> " + spl[0] + '</td></tr>';
$("#mm tbody").append(text);
}
}
}
@import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css");
#div1 {
display: none;
}
#head {
font-size: 18px;
font-weight: bold;
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id='head'></div>
<div>
<table id='mm' class="table table-striped">
<thead>
<th>Sr</th>
<th>Obsolete Data</th>
<th>Updated Data</th>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id='div1'></div>
这篇关于使用Moment或Internationalization API时更正时区列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文