js展示世界各国日期-时间

122

js,jquery展示世界各国日期-时间

如图:

11.png


============ HTML ==============
<div class="world-time mtb40">
    <div class="comm-title">
        <h2>世界时间</h2>
    </div>
    <div class="cons bg-width after">
        <ul>
            <li>
                <h5><em class="icons"></em>北京时间</h5>
                <p class="bj-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>美国东部</h5>
                <p class="usad-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>美国西部</h5>
                <p class="usax-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>法国时间</h5>
                <p  class="france-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>西班牙</h5>
                <p class="spain-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>意大利</h5>
                <p class="italy-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>日本时间</h5>
                <p class="japan-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>英国时间</h5>
                <p class="britain-time">09-12 19:51:01</p>
            </li>
            <li>
                <h5><em class="icons"></em>德国时间</h5>
                <p class="germany-time">09-12 19:51:01</p>
            </li>
        </ul>
    </div>
</div>
============ JS ==============
$(function(){
    window.setInterval("refresh()",10);
});
Date.prototype.format = function(fmt) {
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)){
        fmt = fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o){
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}
function calcTime(date,offset) {
    var utc = date.getTime() + (date.getTimezoneOffset() * 60000);
    var nd = new Date(utc + (3600000*offset));
    return nd;
}

function refresh(){
    var date = new Date();
    $('.bj-time').html(calcTime(date,8).format('MM-dd hh:mm:ss'));
    $('.usad-time').html(calcTime(date,-4).format('MM-dd hh:mm:ss'));
    $('.usax-time').html(calcTime(date,-7).format('MM-dd hh:mm:ss'));
    $('.france-time').html(calcTime(date,1).format('MM-dd hh:mm:ss'));
    $('.spain-time').html(calcTime(date,1).format('MM-dd hh:mm:ss'));
    $('.italy-time').html(calcTime(date,1).format('MM-dd hh:mm:ss'));
    $('.japan-time').html(calcTime(date,9).format('MM-dd hh:mm:ss'));
    $('.britain-time').html(calcTime(date,0).format('MM-dd hh:mm:ss'));
    $('.germany-time').html(calcTime(date,1).format('MM-dd hh:mm:ss'));
}


下载