Created
March 13, 2018 04:40
-
-
Save kaoru-fukusato/0618cf9fba85bc5197078d81bf2a8ab9 to your computer and use it in GitHub Desktop.
コピペで学べるプログラミング基本2-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"><!-- | |
function myFunc(){ | |
myD = new Date(); // 現在時刻 取得 | |
myYear = myD.getFullYear(); // 今年の '年' | |
myNextYear = new Date( myYear+1 , 0 , 1 ); // 来年の1月1日の経過秒を取得 | |
myMsec = myNextYear.getTime() - myD.getTime(); // 来年1月1日 と現在の差(ミリ秒) | |
myNextDay = Math.floor ( myMsec / (1000*60*60*24) ); // '日' を計算 | |
myMsec -= ( myNextDay * (1000*60*60*24) ); // 経過秒から '日' を引く | |
myNextHour = Math.floor ( myMsec / (1000*60*60) ); // '時' を計算 | |
myMsec -= ( myNextHour * (1000*60*60) ); // 経過秒から '時' を引く | |
myNextMin = Math.floor ( myMsec / (1000*60) ); // '分' を計算 | |
myMsec -= ( myNextMin * (1000*60) ); // 経過秒から '分' を引く | |
myNextSec = Math.floor ( myMsec / 1000 ); // '秒' を計算 | |
myDisp = ""; // 文字クリア | |
if ( myNextDay != 0 ) myDisp += myNextDay + "日と "; // 0日なら表示しない | |
if ( myNextHour != 0 ) myDisp += myNextHour + "時間 "; // 0時間なら表示しない | |
if ( myNextMin != 0 ) myDisp += myNextMin + "分 "; // 0分なら表示しない | |
myDisp += myNextSec + "秒"; // 秒セット | |
document.getElementById("countdown").innerHTML = myDisp; | |
} | |
// --></script> | |
来年まで、あと、 <SPAN ID="countdown">カウントダウン</SPAN> です。 | |
<script type="text/javascript"><!-- | |
setInterval( "myFunc()", 1000 ); | |
// --></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment