この記事では、JavaScriptによって北京時間をリアルタイムで表示する方法について説明します。参照のためにそれを共有してください。詳細は次のとおりです。
北京時間は、このページにリアルタイムで表示されます。タイムゾーンの変更は、世界の時間を表示するためにも使用できます。コードは次のとおりです。
次のようにコードをコピーします。<script type = "text/javascript">
date.prototype.strftime = function(format){
var o = {
「M+」:this.getMonth()+1、//月
「D+」:this.getDate()、// day
「H+」:this.gethours()、// hour
「M+」:this.getMinutes()、// minuts
「S+」:this.getSeconds()、// second
「Q+」:math.floor((this.getmonth()+3)/3)、//四半期
「S」:this.getMilliseConds()// millisecond
}
if(/(y+)/。test(format)){
format = format.replace(regexp。$ 1、(this.getthylowear()+"")。subst(4 -regexp。$ 1.Length));
}
for(var k in o){
if(new regexp( "(" + k + ")")。test(format)){
format = format.Replace(regexp。$ 1、regexp。$ 1.length == 1?o [k] :( "00"+ o [k])。subst(( ""+ o [k])。
}
}
返品形式。
}
関数UtctolocalTimestring(d、format){
VAR TimeOffsetInhours =(new Date()。getTimeZoneOffset()/60) + -10;
d.sethours(d.gethours() + timeoffsetinhours);
D.Strftime(フォーマット)を返します。
}
</script>
<スクリプト>
setInterval(function(){var time = utctolocaltimestring(new date()、 'yyyy/mm/dd hh:mm:ss'); document.getElementbyid( "bjtime")。innerhtml = time;}、1000);
</script>
<span id = "bjtime"> </span>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。