JavaScript





2. サンプルプログラム
2.1 日付(年月日)の表示
このページを読み込んだ日付(年月日)を表示するサンプリプログラムを示す。
表示する日付は、画像ファイルとして 0〜9、/ を下表のように用意しておく必要がある。 なお、.gif ファイルを使用する事で背景を透過させる事も可能である。
以下にサンプルプログラムと実行結果を示す。

0.gif

1.gif

2.gif

3.gif

4.gif

5.gif

6.gif

7.gif

8.gif

9.gif

s.gif


<SCRIPT language="JavaScript">
<!--
ndate=new Date();
ye=""+ndate.getYear();
mo=ndate.getMonth()+1;
mo="0"+mo;
da="0"+ndate.getDate();
ye=ye.substring(ye.length-2,ye.length+1);
mo=mo.substring(mo.length-2,mo.length+1);
da=da.substring(da.length-2,da.length+1);
ye10=ye.charAt(0);ye1=ye.charAt(1);
mo10=mo.charAt(0);mo1=mo.charAt(1);
da10=da.charAt(0);da1=da.charAt(1);
document.write('<IMG src="images/'+ye10+'.gif"><IMG src="images/'+ye1+'.gif">');
document.write('<IMG src="images/s.gif">');
document.write('<IMG src="images/'+mo10+'.gif"><IMG src="images/'+mo1+'.gif">');
document.write('<IMG src="images/s.gif">');
document.write('<IMG src="images/'+da10+'.gif"><IMG src="images/'+da1+'.gif">');
// -->
</SCRIPT>













2.2 時間(時計)の表示
このページを読み込んだ時間(時計)を表示するサンプリプログラムを示す。
表示する時間は、画像ファイルとして 0〜9、AM、PM、: を下表のように用意しておく必要がある。 なお、.gif ファイルを使用する事で背景を透過させる事も可能である。
以下にサンプルプログラムと実行結果を示す。


0.gif

1.gif

2.gif

3.gif

4.gif

5.gif

6.gif

7.gif

8.gif

9.gif

am.gif

pm.gif

colon.gif

<SCRIPT language="JavaScript">
<!--
ndate=new Date;
ho="0"+ndate.getHours();
mi="0"+ndate.getMinutes();
if(12<=ho){
if(ho==12){t="pm";}
else{ho="0"+(ho-12);t="pm";}}
else{
if(ho==0){ho=""+12;t="am";}
t="am";}
ho=ho.substring(ho.length-2,ho.length+1);
mi=mi.substring(mi.length-2,mi.length+1);
ho10=ho.charAt(0);ho1=ho.charAt(1);
mi10=mi.charAt(0);mi1=mi.charAt(1);
document.write('<IMG src="l.gif"><IMG src="'+t+'.gif"><IMG src="'+ho10+'.gif">');
document.write('<IMG src="'+ho1+'.gif"><IMG src="colon.gif">');
document.write('<IMG src="'+mi10+'.gif">');
document.write('<IMG src="'+mi1+'.gif"><IMG src="r.gif">');
// -->
</SCRIPT>