js 獲取指定時區當前時間


 var timezone = 8; //目標時區時間,東八區   東時區正數 西市區負數
      var offset_GMT = new Date().getTimezoneOffset(); // 本地時間和格林威治的時間差,單位為分鍾
      var nowDate = new Date().getTime(); // 本地時間距 1970 年 1 月 1 日午夜(GMT 時間)之間的毫秒數
      var targetDate = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000);
      var nowTime=targetDate.getFullYear() + "-" + parseInt(targetDate.getMonth() + 1)  + "-" + targetDate.getDate()+" "+targetDate.getHours()+":"+targetDate.getMinutes()+":"+targetDate.getSeconds();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM