茨城県のホームページ制作会社 -ストロールネット-

時刻をリアルタイムで表示する

setTimeout()を使用し、時刻をリアルタイムで表示します。


サンプル


サンプルソース

<form name="setTimeForm"><input type="text" size="25" name="setTimeText" ID="setTimeText" /></form>
<script type="text/javascript">
<!--
   day = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
   myFunc();
   function myFunc(){
      acy = (new Date()).getYear();
      act = (new Date()).getMonth() + 1;
      acd = (new Date()).getDate();
      acw = (new Date()).getDay();
      ach = (new Date()).getHours();
      acm = (new Date()).getMinutes();
      acs = (new Date()).getSeconds();
      if(act < 10) act = "0" + act;
      if(acd < 10) acd = "0" + acd;
      if(ach < 10) ach = "0" + ach;
      if(acm < 10) acm = "0" + acm;
      if(acs < 10) acs = "0" + acs;
      document.setTimeForm.setTimeText.value = acy+"/"+act+"/"+acd+" ("+day[acw]+") "+ach+":"+acm+":"+acs;
      setTimeout("myFunc()",1000);
   }
//-->
</script>

無料お見積もり
※JavaScriptを有効にしてください。
株式会社ストロールネット
〒309-1722
茨城県笠間市平町1647番地4-204号
TEL:0296-73-4282
FAX:0296-73-4282
E-mail:info@strollnet.com
 お問い合わせ