指定した日付の年・月・日を表示する
サンプルソース
<script language="Javascript"> <!-- d = new Date(); yy = d.getFullYear(); mm = d.getMonth() + 1; dd = d.getDate(); document.write(yy + "/" + mm + "/" + dd); --> </script> |
解説
getFullYear()で年(西暦4桁)を、getMonth()で月を、getDate()で日を取得します。getMonth()は実際の月より1少ない値を返します。例えば1月なら0、12月なら11になります。
実行結果
関連する内容