js---10時間類
阿新 • • 發佈:2017-05-10
get name script ret h+ text val 時間 返回
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>無標題文檔</title> <script> /* 系統時間對象 */ // alert( new Date() ); // 當前系統的時間對象 // myTime typeof object window.onload = function () { var oBody = document.body; setInterval( fnTime,1000 ); fnTime (); function fnTime () { var myTime = new Date(); // number var iYear = myTime.getFullYear(); var iMonth = myTime.getMonth()+1; var iDate = myTime.getDate(); var iWeek = myTime.getDay(); var iHours = myTime.getHours();var iMin = myTime.getMinutes(); var iSec = myTime.getSeconds(); var str = ‘‘; if( iWeek === 0 ) iWeek = ‘星期日‘; if( iWeek === 1 ) iWeek = ‘星期一‘; if( iWeek === 2 ) iWeek = ‘星期二‘; if( iWeek === 3 ) iWeek = ‘星期三‘; if( iWeek === 4 ) iWeek = ‘星期四‘;if( iWeek === 5 ) iWeek = ‘星期五‘; if( iWeek === 6 ) iWeek = ‘星期六‘; str = iYear+ ‘年‘ +iMonth+‘月‘+iDate+‘日 ‘+iWeek+‘ ‘+ toTwo(iHours)+‘ : ‘+ toTwo(iMin)+‘ : ‘+ toTwo(iSec); oBody.innerHTML = str; } }; // alert( toTwo(5) ); // ‘05‘ // alert( toTwo(15) ); // ‘15‘ function toTwo ( n ) { return n < 10 ? ‘0‘ + n : ‘‘ + n; } </script> </head> <body style="font-size:60px;"> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>無標題文檔</title> <script> window.onload = function () { var oBody = document.body; var oP = document.getElementById(‘time‘); var aImg = document.getElementsByTagName(‘img‘); setInterval( fnTime, 1000 ); fnTime (); function fnTime () { var myTime = new Date(); var iHours = myTime.getHours(); var iMin = myTime.getMinutes(); var iSec = myTime.getSeconds(); var str = toTwo(iHours)+toTwo(iMin)+toTwo(iSec); // str = ‘214204‘; oP.innerHTML = str; // str.charAt(5) // aImg[4].src = ‘img/‘ + str.charAt(4) + ‘.JPG‘; // aImg[5].src = ‘img/‘ + str.charAt(5) + ‘.JPG‘; for ( var i=0; i<str.length; i++ ) { aImg[i].src = ‘img/‘ + str.charAt(i) + ‘.JPG‘; } } }; function toTwo ( n ) { return n < 10 ? ‘0‘ + n : ‘‘ + n; } </script> </head> <body> <p id="time" style="font-size:60px;"></p> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> <img src="img/0.JPG" /> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>無標題文檔</title> <script> // 現在的時間點(在變) // 未來的時間點(不變) var iNow = new Date();//返回毫秒數 // var iNew = new Date( 2013, 10, 27, 21,56,0 ); var iNew = new Date( ‘November 27,2013 22:3:0‘ ); var t = Math.floor((iNew - iNow)/1000);//floor() 去掉小數點 // 毫秒 - 秒 var str = Math.floor(t/86400)+‘天‘+Math.floor(t%86400/3600)+‘時‘+Math.floor(t%86400%3600/60)+‘分‘+t%60+‘秒‘; alert( str ); // 天:Math.floor(t/86400) // 時:Math.floor(t%86400/3600) // 分:Math.floor(t%86400%3600/60) // 秒:t%60 // 數字形式:new Date( 2013,4,1,9,48,12 ); // 字符串形式:new Date(‘June 10,2013 12:12:12‘); // January、February、March、April、May、June、 // July、August、September、October、November、December </script> </head> <body> </body> </html>
js---10時間類