close
文章出處
寫在前面
寫了一遍又一遍,網頁老卡住,沒保存下來,不寫了。
時間轉換代碼
//獲得北京時間 Date.prototype.getBJDate = function () { //獲得當前運行環境時間 var d = new Date(), currentDate = new Date(), tmpHours = currentDate.getHours(); //算得時區 var time_zone = -d.getTimezoneOffset() / 60; //少于0的是西區 西區應該用時區絕對值加京八區 重新設置時間(西區時間比東區時間早 所以加時區間隔) if (time_zone < 0) { time_zone = Math.abs(time_zone) + 8; currentDate.setHours(tmpHours + time_zone); } else { //大于0的是東區 東區時間直接跟京八區相減 time_zone -= 8; currentDate.setHours(tmpHours - time_zone); } return currentDate; }
![]() |
不含病毒。www.avast.com |
全站熱搜