対象ファイルへのアクセス日と対象ファイルの最終更新日を表示します。
動的ページの場合は、アクセス日=更新日となりますのでご注意を。

サンプル

サンプルソース

JavaScript + CSS

<script type="text/javascript">
<!--
	day = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	// アクセス日時
	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.write("アクセス日時:");
	document.write(acy+"/"+act+"/"+acd+" ("+day[acw]+") "+ach+":"+acm+":"+acs);

	// 最終更新日
	document.write("<br />");
	lmy = (new Date(document.lastModified)).getYear();
	lmt = (new Date(document.lastModified)).getMonth() + 1;
	lmd = (new Date(document.lastModified)).getDate();
	lmw = (new Date(document.lastModified)).getDay();
	lmh = (new Date(document.lastModified)).getHours();
	lmm = (new Date(document.lastModified)).getMinutes();
	lms = (new Date(document.lastModified)).getSeconds();
	if(lmt < 10) lmt = "0" + lmt;
	if(lmd < 10) lmd = "0" + lmd;
	if(lmh < 10) lmh = "0" + lmh;
	if(lmm < 10) lmm = "0" + lmm;
	if(lms < 10) lms = "0" + lms;
	document.write("最終更新日:");
	document.write(lmy+"/"+lmt+"/"+lmd+" ("+day[lmw]+") "+lmh+":"+lmm+":"+lms);
//-->
</script>
カテゴリ: JavaScript 2010/04/20 3:14

コメントをどうぞ