本日  昨日
 
03/16(Sun) 02:06

o 訪問日・ファイル最終更新日の表示
(99.05.09)2000年対応ルーチンの追加
(99.05.05)「ファイル最終更新日表示」の2個の重大バグを修正。これまでにダウンされた方は変更をよろしくお願い致します。
・IEで5月1日が4月31日と表示されるという月変わり処理の不具合を修正。
・IE5.0バージョン判定でIE5.0のappVersionが5ではなく4であることの修正。
(99.04.04)「ファイル最終更新日表示」にIE5.0の処理を追加しました。


ページへの訪問日、ファイルの最終更新日を表示するスクリプトです。表示例を下に示します。
  1. JavaScriptの中でlastModifiedはサーバから値をもらう唯一の命令ですが、サーバによっては値を返さないサーバがあります。値を返さないサーバの場合は、NetscapeとIE5.0では1970年1月1日0時(ローカルタイム)、IE4.01以下では1970年1月1日9時(グリニッジ標準時)が表示されます。
  2. また、サーバによっては(infowebはこれ)訪問日(アクセス日)をセットするものもあります。この2つに該当するプロバイダの方は、最終更新日は使えません。
  3. SSIが使えるサーバであればSSIで表示しましょう。

設置方法
下のスクリプトをコピーし、<BODY>と</BODY>のなかの時刻表示したい場所に貼りつけます。

ページへの訪問日

  1. new Date()はパラメータを指定しないと現在時刻を取得します。
  2. ((now.getMinutes() < 10) ? "0" : "")は、数値が9以下の場合頭に0を付ける処理です。スクリプトでは「分」「秒」に適用してますが、「月」「日」「時」にも適用することができます。
<script language="JavaScript"> <!-- // 訪問日表示 now = new Date(); year = now.getYear(); if (year < 2000) year = year + 1900; month = now.getMonth()+1; day = now.getDate(); week = now.getDay(); hour = now.getHours(); min = ((now.getMinutes() < 10) ? "0" : "") + now.getMinutes(); sec = ((now.getSeconds() < 10) ? "0" : "") + now.getSeconds(); wk = new Array("日","月","火","水","木","金","土"); document.write("◆訪問日:"+year+"年"+month+"月"+day+"日("+wk[week]+") "); document.write(+hour+"時"+min+"分"+sec+"秒<br>"); // --> </script>

ファイルの最終更新日

  1. document.lastModifiedにファイルの最終更新日がセットされているので、この値をnew Date()に代入して最終更新日を取得します。
  2. document.lastModifiedには、NetscapeおよびIE5.0ではローカルタイムがIE4.01以下ではグリニッジ標準時(-9時間)がセットされます。if文でブラウザを判定しIE4.01以下の補正処理をします。
<script language="JavaScript"> <!-- // 更新日表示 now = new Date(document.lastModified); if(navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.charAt(navigator.appVersion.indexOf("MSIE",0)+5) <= 4) { now.setTime(now.getTime() + 9*60*60*1000); } year = now.getYear(); if (year < 2000) year = year + 1900; month = now.getMonth()+1; day = now.getDate(); week = now.getDay(); hour = now.getHours(); min = ((now.getMinutes() < 10) ? "0" : "") + now.getMinutes(); sec = ((now.getSeconds() < 10) ? "0" : "") + now.getSeconds(); wk = new Array("日","月","火","水","木","金","土"); document.write("◆更新日:"+year+"年"+month+"月"+day+"日("+wk[week]+") "); document.write(+hour+"時"+min+"分"+sec+"秒<br>"); // --> </script>

 
 
©1997- Kikuchisan's workshop All rights reserved //

スポンサーリンク

関連コンテンツ