代表者の戯言

month&time



This time,I want to tell you how to express month & time using JavaScript.


******************************************************************************************************

<!DOCTYPE html>


<html lang="ja">


<head>


<meta charset="UTF-8">


<title></title>


<link rel="stylesheet" href="reset.css">


<link rel="stylesheet" href="main.css">


</head>


<body>


<div class="container">


<button id="btn1" class="button">年</button>


<button id="btn2" class="button">月</button>


<button id="btn3" class="button">日</button>


<button id="btn4" class="button">時間</button>


<button id="btn5" class="button">分</button>


<button id="btn6" class="button">秒</button>


</div>


<script type="text/javascript">


var today=new Date();


var years;


var months;


var days;


var hours;


var minutes;


var seconds;


years="";


months="";


days="";


hours="";


minutes="";


seconds="";


years = today.getFullYear();


months = today.getMonth() + 1;


days = today.getDate();


hours = today.getHours();


minutes = today.getMinutes();


seconds = today.getSeconds();


document.getElementById("btn1").addEventListener("click", () => {


alert(years+"年");


});


document.getElementById("btn2").addEventListener("click", () => {


alert(months+"月");


});


document.getElementById("btn3").addEventListener("click", () => {


alert(days+"日");


});


document.getElementById("btn4").addEventListener("click", () => {


alert(hours+"時");


});


document.getElementById("btn5").addEventListener("click", () => {


alert(minutes+"分");


});


document.getElementById("btn6").addEventListener("click", () => {


alert(seconds+"秒");


});


</script>


</body>


</html>


******************************************************************************************************
screen