<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>2000年から本日までの年だけを全て表示</title>
</head>
<body>
<script>
document.write('<p>' + '↓現在日時分秒を取得(new Dateメソッド)' + '</p>') // ←任意行
var date = new Date();
document.write('<p>' + date + '</p>') // ←任意行
document.write('<p>' + '↓現在日時から「年」のみを取得(getFullYeaメソッド)' + '</p>') // ←任意行
var year = date.getFullYear();
document.write('<p>' + year +'がyaerに入る' + '</p>') // ←任意行
document.write('<p>' + '↓初期値を設定' + '</p>') // ←任意行
for (var i = 2000; i<= year; i++) {
document.write('<p>' + i + '</p>')
}
</script>
</body>
</html>
More than 3 years have passed since last update.
【JavaScript】繰り返し処理を利用し、西暦2000年から本日までの西暦の年のみを全て表示
Last updated at Posted at 2021-05-07
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme