原生态javascript获取日期 复制代码 代码如下: <BR>var myDate = new Date();<BR> myDate.getYear(); //获取当前年份(2位)<BR> myDate.getFullYear(); //获取完整的年份(4位,1970-????)<BR> myDate.getMonth(); //获取当前月份(0-11,0代表1月)<BR> myDate.getDate(); //获取当前日(1-31)<BR> myDate.getDay(); //获取当前星期X(0-6,0代表星期天)<BR> myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)<BR> myDate.getHours(); //获取当前小时数(0-23)<BR> myDate.getMinutes(); //获取当前分钟数(0-59)<BR> myDate.getSeconds(); //获取当前秒数(0-59)<BR> myDate.getMilliseconds(); //获取当前毫秒数(0-999)<BR> myDate.toLocaleDateString(); //获取当前日期<BR> var mytime=myDate.toLocaleTimeString(); //获取当前时间<BR> myDate.toLocaleString( ); //获取日期与时间<BR>if (mytime<"23:30:00")<BR>{<BR>alert(mytime);<BR>}<BR> 基于jquery获取日期 复制代码 代码如下: 当期时间 <BR> .date{height:100px;line-height:100px;margin:0 auto;font-family:Arial, Helvetica, sans-serif;font-size:40px;<BR> border:solid 1px #ccc;box-shadow:0 0 3px rgba(0,0,0,0.3) inset;border-radius:5px;text-shadow:1px 1px 2px rgba(0,0,0,0.3);}<BR> .date strong{padding:0 10px;display:inline-block;height:100px;border-right:solid 1px #ccc;}<BR> js简单的获取当前日期和时间 <BR> $(document).ready(function(){<BR> setInterval(showTime, 1000); <BR> function timer(obj,txt){<BR> obj.text(txt);<BR> } <BR> function showTime(){ <BR> var today = new Date();<BR> var weekday=new Array(7)<BR> weekday[0]="星期一"<BR> weekday[1]="星期二"<BR> weekday[2]="星期三"<BR> weekday[3]="星期四"<BR> weekday[4]="星期五"<BR> weekday[5]="星期六"<BR> weekday[6]="星期日" <BR> var y=today.getFullYear()+"年";<BR> var month=today.getMonth()+"月";<BR> var td=today.getDate()+"日";<BR> var d=weekday[today.getDay()];<BR> var h=today.getHours();<BR> var m=today.getMinutes();<BR> var s=today.getSeconds(); <BR> timer($("#Y"),y);<BR> timer($("#MH"),month); <BR> timer($("#TD"),td); <BR> timer($("#D"),d);<BR> timer($("#H"),h);<BR> timer($("#M"),m);<BR> timer($("#S"),s);<BR> } <BR> })<BR> 可判断早上好晚上好代码 复制代码 代码如下: <BR>//定义一个tick函数,以获取系统的时间<BR>function tick()<BR>{<BR>var year,month,day,hours,minutes,seconds,ap;<BR>var intYear,intMonth,intDay,intHours,intMinutes,intSeconds;<BR>var today;<BR>today=new Date();<BR>intYear=today.getYear();<BR>intMonth=today.getMonth()+1;<BR>intDay=today.getDate();<BR>intHours=today.getHours();<BR>intMinutes=today.getMinutes();<BR>intSeconds=today.getSeconds();<BR>//获取系统时间的小时数<BR>if(intHours==0)<BR>{<BR>hours=intHours+":";<BR>ap="凌晨";<BR>}<BR>else if(intHours<12)<BR>{<BR>hours=intHours+":";<BR>ap="早晨";<BR>}<BR>else if(intHours==12)<BR>{<BR>hours=intHours+":";<BR>ap="中午";<BR>}<BR>else<BR>{<BR>intHours=intHours-12;<BR>hours=intHours+":";<BR>ap="下午";<BR>}<BR>//获取系统时间的分数<BR>if(intMinutes<10)<BR>{<BR>minutes="0"+intMinutes+":";<BR>}<BR>else<BR>minutes=intMinutes+":";<BR>//获取系统时间的秒数<BR>if(intSeconds<10)<BR>seconds="0"+intSeconds+" ";<BR>else<BR>seconds=intSeconds+" ";<BR>timeString=year+month+day+hours+minutes+seconds+ap;<BR>Clock.innerHTML=timeString;<BR>//每隔0.1秒钟执行一次tick函数<BR>window.setTimeout("tick()",100);<BR>}<BR>window.onload=tick;<BR>下面这句是调用函数