我有一个带有 javascript 的时钟我想通过 javascript 将这个时钟的拉丁数字更改为阿拉伯数字,我尝试了以下代码,但它不起作用。如何解决?
演示:http: //jsfiddle.net/NdzHg/
<script type="text/javascript">
var interval = self.setInterval("clock()", 1000);
function clock() {
var rep = {
'0': '۰',
'1': '۱',
'2': '۲',
'3': '۳',
'4': '۴',
'5': '۵',
'6': '۶',
'7': '۷',
'8': '۸',
'9': '۹',
}
var date = new Date();
var hourOffset = 4;
date.setUTCHours(date.getUTCHours(), date.getUTCMinutes());
var time = date.getTime();
date.setUTCFullYear(date.getUTCFullYear(), 3, 21);
var dstStart = date.getTime();
date.setUTCFullYear(date.getUTCFullYear(), 9, 22);
var dstEnd = date.getTime();
if (time > dstStart && time < dstEnd){ hourOffset = 4;}
date.setUTCHours(date.getUTCHours() + hourOffset, date.getUTCMinutes() + 30);
var output = date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds();
for (key in rep) {
str = output.split(key).join(rep[key]);
}
$("#clock").html(str);
}
</script>
<div id="clock"></div>