Java Scriptって何?
Java Scriptに初めて触れる方はまずこちらへ。
タグの絵本
>
Java Script
> 現在の日付と時刻を表示
■ 現在の日付と時刻を表示
サンプル
プログラムソース&解説
<script language="JavaScript"> <!-- nowyoubi = new Array("日","月","火","水","木","金","土"); nowdata = new Date(); nowyear = nowdata.getYear() nowmonth = nowdata.getMonth() + 1; nowdate = nowdata.getDate(); nowday = nowdata.getDay(); nowhour = nowdata.getHours(); nowmin = nowdata.getMinutes(); nowsec = nowdata.getSeconds(); txt1 = nowyear + "年" + nowmonth + "月" + nowdate + "日"; txt2 = nowyoubi[nowday] + "曜日"; txt3 = nowhour + "時" + nowmin + "分" + nowsec + "秒"; txt = txt1 + " " + txt2 + " " + txt3; document.write( txt ); // --> </script>
上記プログラムをBODY内の表示したい場所に書き込みます。
使用例
ソース (テスト書き込み可)
<html> <head> <title>あなたのホームページ</title> </head> <body> ホームページ作成中。頑張ります! <BR><BR> <script language="JavaScript"> <!-- nowyoubi = new Array("日","月","火","水","木","金","土"); nowdata = new Date(); nowyear = nowdata.getYear() nowmonth = nowdata.getMonth() + 1; nowdate = nowdata.getDate(); nowday = nowdata.getDay(); nowhour = nowdata.getHours(); nowmin = nowdata.getMinutes(); nowsec = nowdata.getSeconds(); txt1 = nowyear + "年" + nowmonth + "月" + nowdate + "日"; txt2 = nowyoubi[nowday] + "曜日"; txt3 = nowhour + "時" + nowmin + "分" + nowsec + "秒"; txt = txt1 + " " + txt2 + " " + txt3; document.write( txt ); // --> </script> </body> </html>
あなたのホームページ
-Internet Explorer
ファイル(F) 編集(E) 表示(V) お気に入り(A) ツール(T) ヘルプ(H)
ホームページ作成中。頑張ります!
Copyright (C) 2006 タグの絵本 All rights reserved.
→
index