[JavaScript] 实时显示北京时间 →→→→→进入此内容的聊天室

来自 , 2021-04-08, 写在 JavaScript, 查看 137 次.
URL http://www.code666.cn/view/1f74a54f
  1. <script type="text/javascript">
  2. Date.prototype.strftime = function(format){
  3.         var o = {
  4.           "M+" :  this.getMonth()+1,  //month
  5.           "d+" :  this.getDate(),     //day
  6.           "h+" :  this.getHours(),    //hour
  7.       "m+" :  this.getMinutes(),  //minute
  8.       "s+" :  this.getSeconds(), //second
  9.       "q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
  10.       "S"  :  this.getMilliseconds() //millisecond
  11.         }
  12.  
  13.         if(/(y+)/.test(format)) {
  14.                 format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  15.         }
  16.  
  17.    for(var k in o) {
  18.     if(new RegExp("("+ k +")").test(format)) {
  19.       format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
  20.     }
  21.    }
  22.         return format;
  23. }
  24.  
  25. function UTCToLocalTimeString(d, format) {    
  26.      var   timeOffsetInHours = (new Date().getTimezoneOffset()/60)  + -10;    
  27.     d.setHours(d.getHours() + timeOffsetInHours);
  28.     return d.strftime(format);
  29. }
  30. </script>
  31.  
  32. <script >
  33.         setInterval(function(){var time = UTCToLocalTimeString(new Date(),'yyyy/MM/dd hh:mm:ss');document.getElementById("bjTime").innerHTML = time;},1000);
  34. </script>
  35. <span  id="bjTime"></span>     
  36. //javascript/1075

回复 "实时显示北京时间"

这儿你可以回复上面这条便签

captcha