JS获取当前时间 |
您所在的位置:网站首页 › js怎么显示当前时间 › JS获取当前时间 |
JS获取当前时间.txt如果你看到面前的阴影,别怕,那是因为你的背后有阳光!我允许你走进我的世界,但绝不允许你在我的世界里走来走去。SCRIPT LANGUAGE="JavaScript" var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-????) myDate.getMonth(); //获取当前月份(0-11,0代表1月) myDate.getDate(); //获取当前日(1-31) myDate.getDay(); //获取当前星期X(0-6,0代表星期天) myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数) myDate.getHours(); //获取当前小时数(0-23) myDate.getMinutes(); //获取当前分钟数(0-59) myDate.getSeconds(); //获取当前秒数(0-59) myDate.getMilliseconds(); //获取当前毫秒数(0-999) myDate.toLocaleDateString(); //获取当前日期 var mytime=myDate.toLocaleTimeString(); //获取当前时间 myDate.toLocaleString( ); //获取日期与时间 if (mytime"23:30:00"){ alert(mytime); } /SCRIPT
2.% //日期转换 java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date currentTime = new java.util.Date();//得到当前系统时间 String str_date1 = formatter.format(currentTime); //将日期时间格式化 String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式 %
1. 2008年11月13日 星期四 上午 10:13:46 div id="Clock" align="center" style="font-size: 15px; color:#000000"/div script function tick() { var hours, minutes, seconds, xfile; var intHours, intMinutes, intSeconds; var today, theday; today = new Date(); function initArray(){ this.length=initArray.arguments.length for(var i=0;ithis.length;i++) this[i+1]=initArray.arguments[i] } var d=new initArray( " 星期日", " 星期一", " 星期二", " 星期三", " 星期四", " 星期五", " 星期六"); theday = today.getYear()+"年" + [today.getMonth()+1]+"月" +today.getDate()+"日" + d[today.getDay()+1]; intHours = today.getHours(); intMinutes = today.getMinutes(); intSeconds = today.getSeconds(); if (intHours == 0) { hours = "12:"; xfile = " 午夜 "; } else if (intHours 12) { hours = intHours+":"; xfile = " 上午 "; } else if (intHours == 12) { hours = "12:"; xfile = " 正午 "; } else { intHours = intHours - 12 hours = intHours + ":"; xfile = " 下午 "; } if (intMinutes 10) { minutes = "0"+intMinutes+":"; } else { minutes = intMinutes+":"; } if (intSeconds 10) { seconds = "0"+intSeconds+" "; } else { seconds = intSeconds+" "; } timeString = theday+xfile+hours+minutes+seconds; Clock.innerHTML = timeString; window.setTimeout("tick();", 100); } window.onload = tick; /script
2. 2008年11月13 星期四 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |