Buscar

Javascript Date Image

Hai hai...
Kalender di javascript banyak bentuknya. Kali ini saya lagi coba mambuat kalender dengan menggunakan gambar.
Hasilnya seperti di bawah ini :
Kita cukup membuat script di bawah ini :
<head>
<script language="JavaScript">

theDate= new Date();
months = new Array();
days = new Array();

months[1] ="jan.gif";
months[2] ="feb.gif";
months[3] ="mar.gif";
months[4] ="apr.gif";
months[5] ="may.gif";
months[6] ="jun.gif";
months[7] ="jul.gif";
months[8] ="aug.gif";
months[9] ="sep.gif";
months[10] ="oct.gif";
months[11] ="nov.gif";
months[12] ="dec.gif";
days[1] ="1st.gif";
days[2] ="2nd.gif";
days[3] ="3rd.gif";
days[4] ="4th.gif";
days[5] ="5th.gif";
days[6] ="6th.gif";
days[7] ="7th.gif";
days[8] ="8th.gif";
days[9] ="9th.gif";
days[10] ="10th.gif";
days[11] ="11th.gif";
days[12] ="12th.gif";
days[13] ="13th.gif";
days[14] ="14th.gif";
days[15] ="15th.gif";
days[16] ="16th.gif";
days[17] ="17th.gif";
days[18] ="18th.gif";
days[19] ="18th.gif";
days[20] ="20th.gif";
days[21] ="21st.gif";
days[22] ="22nd.gif";
days[23] ="23rd.gif";
days[24] ="24th.gif";
days[25] ="25th.gif";
days[26] ="26th.gif";
days[27] ="27th.gif";
days[28] ="28th.gif";
days[29] ="29th.gif";
days[30] ="30th.gif";
days[31] ="31st.gif";

function printDate() {
 document.write('<img src="' + months[theDate.getMonth()+1] + '">'); //bulan 
 document.write('</br>');
 document.write('<img src="' + days[theDate.getDate()] + '">'); // hari
 document.write('<font style="font-family:Verdana, Geneva, sans-serif; size:19px; color:#F0F">' + theDate.getFullYear() + '</font>'); // tahun
}

</script>
</head>
<body>

<center>

<script>
 printDate();
</script>

</center>
</body>

Ada satu hal yang harus diperhatikan , mengapa script untuk mengambil bulan (theDate.getMonth()+1) harus menggunakan +1 ? karena Javascript menghitung bulan dari 0 sampai 11, itu berarti untuk Januari 0 dan Desember 11, maka harus di tambah 1. Hehehe...
Jangan lupa download image nya disini yaa..klik DOWNLOAD IMAGE , lalu simpan di folder aplikasi kamu.
Oh iya Image ini sumbernya dari http://www.site-ations.com dan http://www.bruce-hamilton.com
Selamat mencoba :)

0 comments:

Posting Komentar