LoginSignup
0
0

More than 1 year has passed since last update.

現在時間を表示させる

Posted at

js:
function set2(num) {
// 桁数が1桁だったら先頭に0を加えて2桁に調整する
let ret;
if (num < 10) { ret = "0" + num; }
else { ret = num; }
return ret;
}
function showClock() {
const nowTime = new Date(); //現在日時
const nowHour = set2(nowTime.getHours()); //時間
const nowMin = set2(nowTime.getMinutes()); //分
const nowSec = set2(nowTime.getSeconds()); //秒
const msg = "現在時刻は、" + nowHour + ":" + nowMin + ":" + nowSec + " です。";
document.getElementById("showTime").innerHTML = msg;
}
setInterval('showClock()', 1000);

html:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0