首页 > 代码库 > js---10时间类
js---10时间类
<!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 = http://www.mamicode.com/‘img/‘ + str.charAt(4) + ‘.JPG‘; // aImg[5].src = http://www.mamicode.com/‘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="http://www.mamicode.com/img/0.JPG" /> <img src="http://www.mamicode.com/img/0.JPG" /> <img src="http://www.mamicode.com/img/0.JPG" /> <img src="http://www.mamicode.com/img/0.JPG" /> <img src="http://www.mamicode.com/img/0.JPG" /> <img src="http://www.mamicode.com/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时间类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。