S一個根據時區輸出時區時間的函數 原

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>根據時區取得時區時間</title>
    <meta name="Blog" content="http://www.cnblogs.com/manfredHu/">
    <meta name="Author" content="manfredHu">
</head>

<body>
    <script type="text/javascript">
    //得到標準時區的時間的函數
    function getLocalTime(i) {
        //參數i爲時區值數字,比如北京爲東八區則輸進8,西5輸入-5
        if (typeof i !== 'number') return;
        var d = new Date();
        //得到1970年一月一日到現在的秒數
        var len = d.getTime();
        //本地時間與GMT時間的時間偏移差
        var offset = d.getTimezoneOffset() * 60000;
		//console.log("offset:" + d.getTimezoneOffset()/60);
        //得到現在的格林尼治時間
        var utcTime = len + offset;
        return new Date(utcTime + 3600000 * i);
    }
    console.log("*******************東區時間************************************");
    console.log("零時區-倫敦時間:" + getLocalTime(0));
    console.log("東一區-柏林時間:" + getLocalTime(1));
    console.log("東二區-雅典時間:" + getLocalTime(2));
    console.log("東三區-莫斯科時間:" + getLocalTime(3));
    console.log("東四區-時間:" + getLocalTime(4));
    console.log("東五區-伊斯蘭堡時間:" + getLocalTime(5));
    console.log("東六區-科倫坡時間:" + getLocalTime(6));
    console.log("東七區-曼谷時間:" + getLocalTime(7));
    console.log("東八區-北京時間:" + getLocalTime(8));
    console.log("東九區-東京時間:" + getLocalTime(9));
    console.log("東十區-悉尼時間:" + getLocalTime(10));
    console.log("東十二區-斐濟時間:" + getLocalTime(12));
    console.log("*******************西區時間************************************");
    console.log("西十區-斐濟時間:" + getLocalTime(-10));
    console.log("西九區-阿拉斯加時間:" + getLocalTime(-9));
    console.log("西八區-太平洋時間(美國和加拿大):" + getLocalTime(-8));
    console.log("西七區-山地時間(美國和加拿大):" + getLocalTime(-7));
    console.log("西六區-中部時間(美國和加拿大):" + getLocalTime(-6));
    console.log("西五區-東部時間(美國和加拿大):" + getLocalTime(-5));
    console.log("西四區-大西洋時間(加拿大):" + getLocalTime(-4));
    console.log("西三區-巴西利亞時間:" + getLocalTime(-3));
    </script>
</body>

</html>

引用:https://www.cnblogs.com/manfredHu/p/4523640.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章